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

Oleg Kalnichevski commented on HTTPCLIENT-2390:
-----------------------------------------------

[~michael-o] "...Для Вас, Козлов, подземный переход построили..."

[~davsclaus] Usually I would be willing to go to any lengths to help out a 
fellow Apache project. In this case however I feel that adding one more config 
knob to tweak would ultimately be a disservice to all parties involved. 

Status codes 307 and 308 have been introduced more than 10 years ago [1] 
specifically to disambiguate the expected behavior in case of 301 and 302 
redirects. There is really no excuse to continue using 301 and 302 and getting 
shocked by the user agent's changing the redirect method to GET. 

Please ask the affected user to ask the API provider to fix their service by 
simply using 307 and 308 in place of 302 and 301. This is all it takes. If they 
refuse, let us know. We will come up with something.

Oleg  

[1] https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.7

> Allow to control HTTP redirect 301/302 to not change POST to GET
> ----------------------------------------------------------------
>
>                 Key: HTTPCLIENT-2390
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2390
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>    Affects Versions: 5.4.4
>            Reporter: Claus Ibsen
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> At Apache Camel we have users reporting a situation with using a graphql 
> service that returns a 301 redirect and this causes the call to fail because 
> the payload is removed due to POST becomes GET. This is correct according to 
> HTTP spec. But often the real world is "different" and it would be good if 
> there was an option or some enhanced API in RedirectStrategy so end users can 
> handle this.
>  
> If you look at the source code in
> org/apache/httpcomponents/client5/httpclient5/5.4.4/httpclient5-5.4.4-sources.jar!/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java:149
> You can see how status 301/302 is forced to change POST to GET. This is what 
> would be good if there was some flag or API to decide not to do that.
>  
> The Apache Camel use-case
> it is v2:
> rest("/v2/swapi-graphql/all-films").get()
> .produces("application/json")
> .to("direct:swapi-graphql-all-films2");
> from("direct:swapi-graphql-all-films2")
> .setBody(constant("\{ allFilms { films { title director releaseDate } } }"))
> .to("graphql://[https://swapi-graphql.netlify.app/.netlify/functions/index]";)
> .convertBodyTo(String.class);
> The reason for the failure is interesting:
> 1. GraphQL component constructs POST and invokes HTTP
> 2. netlify's index URL returns 301 with /graphql  - and that forces POST to
> be changed to GET by underlying http client.
> looking at HTTP spec - it should have been 308
> [https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308] -
> but haven't seen 308 adopted widely.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to