This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 86a60a13a1 Implement clarification that setting a value of null
removes the header
86a60a13a1 is described below
commit 86a60a13a1c18a1f1c494f6e5e418c59c0dd94cf
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Feb 14 09:59:08 2023 +0000
Implement clarification that setting a value of null removes the header
---
java/org/apache/catalina/connector/Response.java | 2 +-
java/org/apache/coyote/Response.java | 10 +++++++++-
webapps/docs/changelog.xml | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/catalina/connector/Response.java
b/java/org/apache/catalina/connector/Response.java
index 6c47a21f40..e44076ed5b 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -1363,7 +1363,7 @@ public class Response implements HttpServletResponse {
@Override
public void setHeader(String name, String value) {
- if (name == null || name.length() == 0 || value == null) {
+ if (name == null || name.length() == 0) {
return;
}
diff --git a/java/org/apache/coyote/Response.java
b/java/org/apache/coyote/Response.java
index 1673e9c3b9..0a0cfb16ca 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -366,7 +366,11 @@ public final class Response {
return;
}
}
- headers.setValue(name).setString(value);
+ if (value == null) {
+ headers.removeHeader(name);
+ } else {
+ headers.setValue(name).setString(value);
+ }
}
@@ -419,6 +423,10 @@ public final class Response {
}
if (name.equalsIgnoreCase("Content-Length")) {
try {
+ if (value == null) {
+ setContentLength(-1);
+ return true;
+ }
long cL = Long.parseLong(value);
setContentLength(cL);
return true;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 843885e5b5..621366b7b2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -180,6 +180,12 @@
<code>HttpServletResponse</code> defined by the Jakarta Servlet project
for the Servlet 6.1 API. (markt)
</add>
+ <fix>
+ Implement the clarification from the Jakarta Servlet project that
+ calling one of the <code>HttpServletResponse</code> methods for setting
+ HTTP header values with <code>null</code> as the new header value
+ removes any existing header of that name. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]