Skip to content

Commit 3454ddd

Browse files
committed
Fix jakartaee#275 - containers can use relative URLS for redirects
1 parent 6727b53 commit 3454ddd

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,22 @@ public interface HttpServletResponse extends ServletResponse {
147147
/**
148148
* Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.
149149
* The buffer will be replaced with the data set by this method. Calling this method sets the status code to
150-
* {@link #SC_FOUND} 302 (Found). This method can accept relative URLs;the servlet container must convert the relative
151-
* URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/'
152-
* the container interprets it as relative to the current request URI. If the location is relative with a leading '/'
153-
* the container interprets it as relative to the servlet container root. If the location is relative with two leading
154-
* '/' the container interprets it as a network-path reference (see <a href="http://www.ietf.org/rfc/rfc3986.txt"> RFC
155-
* 3986: Uniform Resource Identifier (URI): Generic Syntax</a>, section 4.2 &quot;Relative Reference&quot;).
150+
* {@link #SC_FOUND} 302 (Found).
151+
* <p>
152+
* This method accepts both relative and absolute URLs. Absolute URLs passed to this method are used as provided as the
153+
* redirect location URL . A servlet container may provide a container specific option that controls whether relative
154+
* URLs passed to this method are converted to absolute URLs or used as provided for the redirect location URL. If no
155+
* such option is provided then the servlet container must always convert a relative URL passed to this method to an
156+
* absolute URL before using it as the redirect location URL. If converting a relative URL to an absolute URL then:
157+
* <ul>
158+
* <li>If the location is relative without a leading '/' the container interprets it as relative to the current request
159+
* URI.</li>
160+
* <li>If the location is relative with a leading '/' the container interprets it as relative to the servlet container
161+
* root.</li>
162+
* <li>If the location is relative with two leading '/' the container interprets it as a network-path reference (see
163+
* <a href="http://www.ietf.org/rfc/rfc3986.txt"> RFC 3986: Uniform Resource Identifier (URI): Generic Syntax</a>,
164+
* section 4.2 &quot;Relative Reference&quot;).</li>
165+
* </ul>
156166
*
157167
* <p>
158168
* If the response has already been committed, this method throws an IllegalStateException. After using this method, the

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -2512,13 +2512,14 @@ The following convenience methods exist in the
25122512

25132513
* `sendError`
25142514

2515-
The `sendRedirect` method will set the
2516-
appropriate headers and content body to redirect the client to a
2517-
different URL. It is legal to call this method with a relative URL path,
2518-
however the underlying container must translate the relative path to a
2519-
fully qualified URL for transmission back to the client. If a partial
2520-
URL is given and, for whatever reason, cannot be converted into a valid
2521-
URL, then this method must throw an `IllegalArgumentException`.
2515+
The `sendRedirect` method will set the appropriate headers and content body to
2516+
redirect the client to a different URL.
2517+
It is legal to call this method with a relative URL path.
2518+
The underlying container may provide an option to use the relative URL path as
2519+
provided but if no such option is provided it must translate the relative path
2520+
to a fully qualified URL for transmission back to the client.
2521+
If a partial URL is given and, for whatever reason, cannot be converted into a
2522+
valid URL, then this method must throw an `IllegalArgumentException`.
25222523

25232524
The `sendError` method will set the
25242525
appropriate headers and content body for an error message to return to
@@ -8559,6 +8560,10 @@ link:https://github.com/eclipse-ee4j/servlet-api/issues/164[Issue 164]::
85598560
Clarify Javadoc for `ServletResponse` and `HttpServletResponse` methods that are
85608561
NO-OPs once the response has been committed.
85618562

8563+
link:https://github.com/eclipse-ee4j/servlet-api/issues/275[Issue 275]::
8564+
Containers may provide an option to send redirects using a location header with
8565+
a relative URL.
8566+
85628567
link:https://github.com/eclipse-ee4j/servlet-api/issues/325[Issue 325]::
85638568
Clarify the behaviour of `getDateHeader()` and `getIntHeader()` when multiple
85648569
headers with the same name are present in the `HttpServletRequest`. The expected

0 commit comments

Comments
 (0)