[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17172757#comment-17172757
 ] 

Randymo commented on HTTPCLIENT-2105:
-------------------------------------

It seems the issue could be in the AsyncRedirectExec where the new 
state.currentRequest does not get the original entity, which does happen in the 
"classic" RedirectExec. It does still have the AsyncEntityProducer, but I have 
not been able to find where that gets used in the flow to get the actual entity 
body.

classic: 
[https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java#L158-L159]

async: 
[https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java#L157]

The classic uses the ClassicHttpRequest which extends HttpEntityContainer so it 
has the getEntity and setEntity methods while the async uses the 
BasicHttpRequest which does not have those have those methods.

I did _try_ this hack solution, but it +*failed*+. 
{code:java}
 if (state.currentRequest == null) {
                        if 
(SimpleHttpRequest.class.equals(scope.originalRequest.getClass())) {
                            final SimpleHttpRequest simpleHttpRequest = 
SimpleHttpRequests.create(request.getMethod(), redirectUri);
                            simpleHttpRequest.setBody(((SimpleHttpRequest) 
scope.originalRequest).getBody());
                            state.currentRequest = simpleHttpRequest;
                        } else {
                            state.currentRequest = new 
BasicHttpRequest(request.getMethod(), redirectUri);
                        }
                    }
{code}
 The state.currentRequest was being set as a SimpleHttpRequest with the correct 
body, but it still was not actually sending it. Not sure what else I am 
missing, but hopefully this info is useful for you figuring out what is going 
on.

> HttpClient5 makes post call with no body after 307 redirect
> -----------------------------------------------------------
>
>                 Key: HTTPCLIENT-2105
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2105
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (async)
>    Affects Versions: 5.0.1
>            Reporter: Randymo
>            Priority: Major
>
> I have switched from the Apache HttpAsyncClient 4 (4.1.4) library to the 
> httpClient 5 (5.0.1)
> I have found that when I make a POST call with body and get back a 307, the 
> subsequent call does NOT include the data body any more, but it does still 
> contain the Content-Type and Content-Length so the server then hangs waiting 
> to receive the rest of the request which never comes.
>  
>  I do not see anything like this while debugging in the HttpClient5 libs
> {code:java}
> FROM: org.apache.http.impl.client.DefaultRedirectStrategy
>     public HttpUriRequest getRedirect(HttpRequest request, HttpResponse 
> response, HttpContext context) throws ProtocolException {
>         URI uri = this.getLocationURI(request, response, context);
>         String method = request.getRequestLine().getMethod();
>         if (method.equalsIgnoreCase("HEAD")) {
>             return new HttpHead(uri);
>         } else if (method.equalsIgnoreCase("GET")) {
>             return new HttpGet(uri);
>         } else {
>             int status = response.getStatusLine().getStatusCode();
>             return (HttpUriRequest)(status != 307 && status != 308 ? new 
> HttpGet(uri) : RequestBuilder.copy(request).setUri(uri).build());
>         }
>     }{code}
> Here is an example from my logs
> {noformat}
> >> POST /ws/v3/batch HTTP/1.1
> >> User-Agent: Apache-HttpAsyncClient/5.0.1 (Java/11.0.7)
> >> Content-Length: 1043
> >> Content-Type: application/json; charset=UTF-8
> >> Host: ORIGINAL_HOST:4443
> >> Connection: keep-alive
> 2020-08-05T20:52:24,377Z DEBUG 
> [httpclient-dispatch-1][HttpAsyncMainClientExec:97] - ex-00000001: produce 
> request data
> 2020-08-05T20:52:24,378Z DEBUG 
> [httpclient-dispatch-1][HttpAsyncMainClientExec:109] - ex-00000001: produce 
> request data, len 1043 bytes
> 2020-08-05T20:52:24,379Z DEBUG 
> [httpclient-dispatch-1][HttpAsyncMainClientExec:117] - ex-00000001: end of 
> request data
> << HTTP/1.1 307 Temporary Redirect
> << Cache-Control: max-age=300
> << Location: https://NEW_HOST:4443/ws/v3/batch
> << X-Server-Response-Time: 40ms
> << X-Server-Chain: ORIGINAL_HOST
> << X-Server-Timestamp: Wed, 05 Aug 2020 20:52:24 GMT
> << Content-Length: 0
> >> POST /ws/v3/batch HTTP/1.1
> >> User-Agent: Apache-HttpAsyncClient/5.0.1 (Java/11.0.7)
> >> Content-Length: 1043
> >> Content-Type: application/json; charset=UTF-8
> >> Host: NEW_HOST:4443
> >> Connection: keep-alive
> 2020-08-05T20:52:24,722Z DEBUG 
> [httpclient-dispatch-2][HttpAsyncMainClientExec:97] - ex-00000001: produce 
> request data
> 2020-08-05T20:52:24,722Z DEBUG 
> [httpclient-dispatch-2][HttpAsyncMainClientExec:117] - ex-00000001: end of 
> request data
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to