Skip to content

Commit 13220f8

Browse files
Merge pull request jakartaee#500 from markt-asf/fix-issue-159
Fix jakartaee#159 - Clarify behaviour of header methods with null or ""
2 parents 3de9907 + 3767d7f commit 13220f8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

api/src/main/java/jakarta/servlet/http/HttpServletResponse.java

+25-8
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,13 @@ public interface HttpServletResponse extends ServletResponse {
175175
public void sendRedirect(String location) throws IOException;
176176

177177
/**
178-
*
179178
* Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the
180-
* epoch. If the header had already been set, the new value overwrites the previous one. The <code>containsHeader</code>
181-
* method can be used to test for the presence of a header before setting its value.
179+
* epoch. If the header had already been set, the new value overwrites all previous values. The
180+
* <code>containsHeader</code> method can be used to test for the presence of a header before setting its value.
182181
* <p>
183182
* This method has no effect if called after the response has been committed.
183+
* <p>
184+
* This method has no effect if {@code null} is passed for the {@code name} parameter.
184185
*
185186
* @param name the name of the header to set
186187
* @param date the assigned date value
@@ -191,11 +192,12 @@ public interface HttpServletResponse extends ServletResponse {
191192
public void setDateHeader(String name, long date);
192193

193194
/**
194-
*
195195
* Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the
196196
* epoch. This method allows response headers to have multiple values.
197197
* <p>
198198
* This method has no effect if called after the response has been committed.
199+
* <p>
200+
* This method has no effect if {@code null} is passed for the {@code name} parameter.
199201
*
200202
* @param name the name of the header to set
201203
* @param date the additional date value
@@ -205,12 +207,17 @@ public interface HttpServletResponse extends ServletResponse {
205207
public void addDateHeader(String name, long date);
206208

207209
/**
208-
*
209210
* Sets a response header with the given name and value. If the header had already been set, the new value overwrites
210-
* the previous one. The <code>containsHeader</code> method can be used to test for the presence of a header before
211+
* all previous values. The <code>containsHeader</code> method can be used to test for the presence of a header before
211212
* setting its value.
212213
* <p>
213214
* This method has no effect if called after the response has been committed.
215+
* <p>
216+
* This method has no effect if {@code null} is passed for the {@code name} parameter.
217+
* <p>
218+
* Passing {@code null} as the value removes all headers with the given name.
219+
* <p>
220+
* Note that the empty string is a valid header value.
214221
*
215222
* @param name the name of the header
216223
* @param value the header value If it contains octet string, it should be encoded according to RFC 2047
@@ -223,6 +230,12 @@ public interface HttpServletResponse extends ServletResponse {
223230

224231
/**
225232
* Adds a response header with the given name and value. This method allows response headers to have multiple values.
233+
* <p>
234+
* This method has no effect if called after the response has been committed.
235+
* <p>
236+
* This method has no effect if {@code null} is passed for either the {@code name} or {@code value} parameters.
237+
* <p>
238+
* Note that the empty string is a valid header value.
226239
*
227240
* @param name the name of the header
228241
* @param value the additional header value If it contains octet string, it should be encoded according to RFC 2047
@@ -234,10 +247,12 @@ public interface HttpServletResponse extends ServletResponse {
234247

235248
/**
236249
* Sets a response header with the given name and integer value. If the header had already been set, the new value
237-
* overwrites the previous one. The <code>containsHeader</code> method can be used to test for the presence of a header
238-
* before setting its value.
250+
* overwrites all previous values. The <code>containsHeader</code> method can be used to test for the presence of a
251+
* header before setting its value.
239252
* <p>
240253
* This method has no effect if called after the response has been committed.
254+
* <p>
255+
* This method has no effect if {@code null} is passed for the {@code name} parameter.
241256
*
242257
* @param name the name of the header
243258
* @param value the assigned integer value
@@ -252,6 +267,8 @@ public interface HttpServletResponse extends ServletResponse {
252267
* values.
253268
* <p>
254269
* This method has no effect if called after the response has been committed.
270+
* <p>
271+
* This method has no effect if {@code null} is passed for the {@code name} parameter.
255272
*
256273
* @param name the name of the header
257274
* @param value the assigned integer value

spec/src/main/asciidoc/servlet-spec-body.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -8544,6 +8544,10 @@ attributes that must be set on the request as part of an error dispatch.
85448544
link:https://github.com/eclipse-ee4j/servlet-api/issues/95[Issue 95]::
85458545
Clarify that Servlet containers are required to support HTTPS.
85468546

8547+
link:https://github.com/eclipse-ee4j/servlet-api/issues/159[Issue 159]::
8548+
Clarify the behaviour of the various methods for adding headers when passed
8549+
`null` or the empty string.
8550+
85478551
link:https://github.com/eclipse-ee4j/servlet-api/issues/164[Issue 164]::
85488552
Clarify Javadoc for `ServletResponse` and `HttpServletResponse` methods that are
85498553
NO-OPs once the response has been committed.

0 commit comments

Comments
 (0)