You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Justus Pendleton (JIRA)" <ji...@apache.org> on 2012/10/10 02:02:02 UTC
[jira] [Created] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET
Justus Pendleton created HTTPCLIENT-1248:
--------------------------------------------
Summary: LaxRedirectStrategy converts POST to GET
Key: HTTPCLIENT-1248
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
Project: HttpComponents HttpClient
Issue Type: Bug
Reporter: Justus Pendleton
The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
{code}
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(uri);
} else {
return new HttpGet(uri);
}
{code}
This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
{code}
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(uri);
else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
return new HttpPost(uri);
} else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
return new HttpGet(uri);
} else {
throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Resolved] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-1248.
-------------------------------------------
Resolution: Fixed
Fix Version/s: 4.2.2
@Jon
You are right. Redirects with 307 should not be converted to GET. I fixed the issue in both trunk and 4.2.x branch. Please review.
Oleg
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
> Fix For: 4.2.2
>
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13474214#comment-13474214 ]
Oleg Kalnichevski commented on HTTPCLIENT-1248:
-----------------------------------------------
Justus
We are trying to keep HttpClient reasonably well behaved with regards to the HTTP spec compliance per default and provide extension points to override the default behavior if required. All you need to do is to subclass lax or default strategy and override one method to get the behavior you want.
Oleg
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
> Fix For: 4.2.2
>
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Updated] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET
Posted by "Justus Pendleton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justus Pendleton updated HTTPCLIENT-1248:
-----------------------------------------
Affects Version/s: 4.2.1
> LaxRedirectStrategy converts POST to GET
> ----------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Updated] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Justus Pendleton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justus Pendleton updated HTTPCLIENT-1248:
-----------------------------------------
Summary: LaxRedirectStrategy converts POST to GET and throws away body (was: LaxRedirectStrategy converts POST to GET)
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Comment Edited] (HTTPCLIENT-1248) LaxRedirectStrategy
converts POST to GET and throws away body
Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13473136#comment-13473136 ]
Jon Moore edited comment on HTTPCLIENT-1248 at 10/10/12 10:06 AM:
------------------------------------------------------------------
@Justus: This is actually compliant HTTP/1.1 behavor, at least for a 302, and matches what most browsers do. See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3
"Note: RFC 1945 and RFC 2068 specify that the client is not allowed
to change the method on the redirected request. However, most
existing user agent implementations treat 302 as if it were a 303
response, performing a GET on the Location field-value regardless
of the original request method. The status codes 303 and 307 have
been added for servers that wish to make unambiguously clear which
kind of reaction is expected of the client."
RFC 2616 obsoletes RFC 2068. The HTTP-WG has been working on a rewrite of the HTTP/1.1 spec ("httpbis") that is meant to clarify (not change) RFC2616. The section on redirects there reads:
http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-20#page-28
"Note: In HTTP/1.0, only the status codes 301 (Moved Permanently)
and 302 (Found) were defined for the first type of redirect, and
the second type did not exist at all ([RFC1945], Section 9.3).
However it turned out that web forms using POST expected redirects
to change the operation for the subsequent request to retrieval
(GET). To address this use case, HTTP/1.1 introduced the second
type of redirect with the status code 303 (See Other) ([RFC2068],
Section 10.3.4). As user agents did not change their behavior to
maintain backwards compatibility, the first revision of HTTP/1.1
added yet another status code, 307 (Temporary Redirect), for which
the backwards compatibility problems did not apply ([RFC2616],
Section 10.3.8). Over 10 years later, most user agents still do
method rewriting for status codes 301 and 302, therefore this
specification makes that behavior conformant in case the original
request was POST."
On the other hand, if this behavior is happening on a 307 Temporary Redirect, then I'd agree this is a bug:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8
"If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued."
Are you seeing this behavior on a 302 or a 307?
was (Author: jonm):
@Justus: This is actually compliant HTTP/1.1 behavor. See:
http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-20#page-28
"Note: In HTTP/1.0, only the status codes 301 (Moved Permanently)
and 302 (Found) were defined for the first type of redirect, and
the second type did not exist at all ([RFC1945], Section 9.3).
However it turned out that web forms using POST expected redirects
to change the operation for the subsequent request to retrieval
(GET). To address this use case, HTTP/1.1 introduced the second
type of redirect with the status code 303 (See Other) ([RFC2068],
Section 10.3.4). As user agents did not change their behavior to
maintain backwards compatibility, the first revision of HTTP/1.1
added yet another status code, 307 (Temporary Redirect), for which
the backwards compatibility problems did not apply ([RFC2616],
Section 10.3.8). Over 10 years later, most user agents still do
method rewriting for status codes 301 and 302, therefore this
specification makes that behavior conformant in case the original
request was POST."
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Comment Edited] (HTTPCLIENT-1248) LaxRedirectStrategy
converts POST to GET and throws away body
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13473135#comment-13473135 ]
Oleg Kalnichevski edited comment on HTTPCLIENT-1248 at 10/10/12 9:59 AM:
-------------------------------------------------------------------------
Justus
I would say this is the intended behavior. If in the context of your particular application entity enclosing redirects are OK, you probably should be using a custom redirect strategy.
Oleg
was (Author: olegk):
Justus
I would say this is the intended behavior. If in the context of your particular application POST redirects are OK, you probably should be using a custom redirect strategy.
Oleg
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Justus Pendleton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13473585#comment-13473585 ]
Justus Pendleton commented on HTTPCLIENT-1248:
----------------------------------------------
I guess I won't complain too much if this is intended behaviour, though I would have thought unattended behaviour -- rather than human attended browsers -- would be a more common use case for clients of the library. In any case, I would suggest that the Javadoc be enhanced with the above explanation. I didn't expect "automatically redirect all POSTs" to mean "turn them into a GET and throw away the body" :) Then again, I seem to be the only one who has complained so far ;).
Thanks for the quick replies Jon & Oleg!
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
> Fix For: 4.2.2
>
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13473136#comment-13473136 ]
Jon Moore commented on HTTPCLIENT-1248:
---------------------------------------
@Justus: This is actually compliant HTTP/1.1 behavor. See:
http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-20#page-28
"Note: In HTTP/1.0, only the status codes 301 (Moved Permanently)
and 302 (Found) were defined for the first type of redirect, and
the second type did not exist at all ([RFC1945], Section 9.3).
However it turned out that web forms using POST expected redirects
to change the operation for the subsequent request to retrieval
(GET). To address this use case, HTTP/1.1 introduced the second
type of redirect with the status code 303 (See Other) ([RFC2068],
Section 10.3.4). As user agents did not change their behavior to
maintain backwards compatibility, the first revision of HTTP/1.1
added yet another status code, 307 (Temporary Redirect), for which
the backwards compatibility problems did not apply ([RFC2616],
Section 10.3.8). Over 10 years later, most user agents still do
method rewriting for status codes 301 and 302, therefore this
specification makes that behavior conformant in case the original
request was POST."
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET
Posted by "Justus Pendleton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13472888#comment-13472888 ]
Justus Pendleton commented on HTTPCLIENT-1248:
----------------------------------------------
Of course even that is still insufficient because it means the POST body is lost :(. So it it needs to be
final HttpPost post = new HttpPost(uri);
if (request instanceof HttpEntityEnclosingRequest)
{
post.setEntity(((HttpEntityEnclosingRequest) request).getEntity());
}
return post;
> LaxRedirectStrategy converts POST to GET
> ----------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1248) LaxRedirectStrategy converts
POST to GET and throws away body
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13473135#comment-13473135 ]
Oleg Kalnichevski commented on HTTPCLIENT-1248:
-----------------------------------------------
Justus
I would say this is the intended behavior. If in the context of your particular application POST redirects are OK, you probably should be using a custom redirect strategy.
Oleg
> LaxRedirectStrategy converts POST to GET and throws away body
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-1248
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1248
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.1
> Reporter: Justus Pendleton
>
> The LaxRedirectStrategy extends the DefaultRedirectStrategy. The DefaultAsyncRequestDirector calls _redirectStrategy.isRedirected()_ and LaxRedirectStrategy will return *true* on a POST. Then the director calls _redirectStrategy.getRedirect()_. The LaxRedirectStrategy doesn't implement this method so the one in the DefaultRedirectStrategy is called:
> {code}
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> } else {
> return new HttpGet(uri);
> }
> {code}
> This turns the POST into a GET on redirect. IMHO the LaxRedirectStrategy should be
> {code}
> public HttpUriRequest getRedirect(
> final HttpRequest request,
> final HttpResponse response,
> final HttpContext context) throws ProtocolException {
> URI uri = getLocationURI(request, response, context);
> String method = request.getRequestLine().getMethod();
> if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
> return new HttpHead(uri);
> else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
> return new HttpPost(uri);
> } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
> return new HttpGet(uri);
> } else {
> throw new IllegalStateException("Redirect called on un-redirectable http method: " + method);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org