[
https://issues.apache.org/jira/browse/HTTPCLIENT-2144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17310266#comment-17310266
]
Julian Reschke edited comment on HTTPCLIENT-2144 at 3/28/21, 6:01 PM:
----------------------------------------------------------------------
Good question; I'm not very good in reading pseudocode-style specs.
The important point is that the charset parameter (if defined), applies to he
encoding of the payload. For *this* media type, the encoding is always
essentially US-ASCII; mapping of non ASCII characters happens a layer above
using percent-encoding.
The type of *that* encoding is not reflected in the media type; browsers use
complex algorithms to decide which one to use (incl. the encoding if the HTML
page from what the form was served from). Another hint comes from a hidden
form parameter (AFAIR: "\_charset\_").
was (Author: reschke):
Good question; I'm not very good in reading pseudocode-style specs.
The important point is that the charset parameter (if defined), applies to he
encoding of the payload. For *this* media type, the encoding is always
essentially US-ASCII; mapping of non ASCII characters happens a layer above
using percent-encoding.
The type of *that* encoding is not reflected in the media type; browsers use
complex algorithms to decide which one to use (incl. the encoding if the HTML
page from what the form was served from). Another hint comes from a hidden
form parameter (AFAIR: "_charset_").
> encoding of body changes during redirect with status code 307
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-2144
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2144
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Reporter: Andrea
> Priority: Major
> Fix For: 4.5.14
>
>
> Given: A request with content-type „application/x-www-form-urlencoded;
> charset=ISO-8859-1“. When an http status code of 307 is received, then the
> charset of the content-type header is altered to UTF-8 and the body is
> re-encoded in the following transmission.
>
> The log snippet shows that the body changes from
> "echotext=TEST%F6TEST"
> to
> "echotext=TEST%C3%B6TEST".
>
> HttpClient Version: 4.5.13
> h3. code snippet:
>
> {code:java}
> CloseableHttpClient httpclient =
> HttpClientBuilder.create().setRedirectStrategy(new
> LaxRedirectStrategy()).build();
> HttpPost httpPost = new
> HttpPost("http://localhost:8080/Testservlet/redirect/echoTest"); //
> Testservlet responds with http status 307
> List<BasicNameValuePair> nvps = new ArrayList<>();
> nvps.add(new BasicNameValuePair("echotext", "TESTöTEST"));
> httpPost.setEntity(new UrlEncodedFormEntity(nvps,
> Charset.forName("ISO-8859-1")));
> CloseableHttpResponse response = httpclient.execute(httpPost);
> {code}
> h3. log snippet:
> {noformat}
> 2021/03/24 12:40:30:767 MEZ [DEBUG] MainClientExec - Opening connection
> {}->[http://localhost:8080|http://localhost:8080/]
> 2021/03/24 12:40:30:767 MEZ [DEBUG] DefaultHttpClientConnectionOperator -
> Connecting to localhost/127.0.0.1:8080
> 2021/03/24 12:40:30:782 MEZ [DEBUG] DefaultHttpClientConnectionOperator -
> Connection established 127.0.0.1:51227<->127.0.0.1:8080
> 2021/03/24 12:40:30:782 MEZ [DEBUG] MainClientExec - Executing request POST
> /Testservlet/redirect/echoTest HTTP/1.1
> 2021/03/24 12:40:30:782 MEZ [DEBUG] MainClientExec - Target auth state:
> UNCHALLENGED
> 2021/03/24 12:40:30:782 MEZ [DEBUG] MainClientExec - Proxy auth state:
> UNCHALLENGED
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >> POST
> /Testservlet/redirect/echoTest HTTP/1.1
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >>
> Content-Length: 20
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >>
> Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >> Host:
> localhost:8080
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >> Connection:
> Keep-Alive
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >> User-Agent:
> Apache-HttpClient/4.5.13 (Java/1.8.0)
> 2021/03/24 12:40:30:782 MEZ [DEBUG] headers - http-outgoing-0 >>
> Accept-Encoding: gzip,deflate
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >> "POST
> /Testservlet/redirect/echoTest HTTP/1.1[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >>
> "Content-Length: 20[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >>
> "{color:#ffab00}Content-Type: application/x-www-form-urlencoded;
> charset=ISO-8859-1[\r][\n]{color}"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >> "Host:
> localhost:8080[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >> "Connection:
> Keep-Alive[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >> "User-Agent:
> Apache-HttpClient/4.5.13 (Java/1.8.0)[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >>
> "Accept-Encoding: gzip,deflate[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >> "[\r][\n]"
> 2021/03/24 12:40:30:782 MEZ [DEBUG] wire - http-outgoing-0 >>
> "{color:#ffab00}echotext=TEST%F6TEST{color}"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "HTTP/1.1 307
> [\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "Location:
> [http://localhost:8080/Testservlet/echoTest[\r][\n|http://localhost:8080/Testservlet/echoTest%5b/r%5d%5b/n]]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 <<
> "Content-Length: 0[\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "Date: Wed, 24
> Mar 2021 11:40:30 GMT[\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "Keep-Alive:
> timeout=20[\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "Connection:
> keep-alive[\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] wire - http-outgoing-0 << "[\r][\n]"
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 <<
> {color:#ffab00}HTTP/1.1 307{color}
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 << Location:
> [http://localhost:8080/Testservlet/echoTest]
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 <<
> Content-Length: 0
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 << Date: Wed,
> 24 Mar 2021 11:40:30 GMT
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 << Keep-Alive:
> timeout=20
> 2021/03/24 12:40:30:795 MEZ [DEBUG] headers - http-outgoing-0 << Connection:
> keep-alive
> 2021/03/24 12:40:30:795 MEZ [DEBUG] MainClientExec - Connection can be kept
> alive for 20000 MILLISECONDS
> 2021/03/24 12:40:30:795 MEZ [DEBUG] PoolingHttpClientConnectionManager -
> Connection [id: 0][route: {}->[http://localhost:8080|http://localhost:8080/]]
> can be kept alive for 20.0 seconds
> 2021/03/24 12:40:30:795 MEZ [DEBUG] DefaultManagedHttpClientConnection -
> http-outgoing-0: set socket timeout to 0
> 2021/03/24 12:40:30:795 MEZ [DEBUG] PoolingHttpClientConnectionManager -
> Connection released: [id: 0][route:
> {}->[http://localhost:8080][total|http://localhost:8080][total/] available:
> 1; route allocated: 1 of 2; total allocated: 1 of 20]
> 2021/03/24 12:40:30:795 MEZ [DEBUG] LaxRedirectStrategy - Redirect requested
> to location 'http://localhost:8080/Testservlet/echoTest'
> 2021/03/24 12:40:30:811 MEZ [DEBUG] RedirectExec - Redirecting to
> 'http://localhost:8080/Testservlet/echoTest' via
> {}->[http://localhost:8080|http://localhost:8080/]
> 2021/03/24 12:40:30:811 MEZ [DEBUG] RequestAddCookies - CookieSpec selected:
> default
> 2021/03/24 12:40:30:811 MEZ [DEBUG] RequestAuthCache - Auth cache not set in
> the context
> 2021/03/24 12:40:30:811 MEZ [DEBUG] PoolingHttpClientConnectionManager -
> Connection request: [route:
> {}->[http://localhost:8080][total|http://localhost:8080][total/] available:
> 1; route allocated: 1 of 2; total allocated: 1 of 20]
> 2021/03/24 12:40:30:811 MEZ [DEBUG] PoolingHttpClientConnectionManager -
> Connection leased: [id: 0][route:
> {}->[http://localhost:8080][total|http://localhost:8080][total/] available:
> 0; route allocated: 1 of 2; total allocated: 1 of 20]
> 2021/03/24 12:40:30:811 MEZ [DEBUG] DefaultManagedHttpClientConnection -
> http-outgoing-0: set socket timeout to 0
> 2021/03/24 12:40:30:811 MEZ [DEBUG] MainClientExec - Executing request POST
> /Testservlet/echoTest HTTP/1.1
> 2021/03/24 12:40:30:811 MEZ [DEBUG] MainClientExec - Target auth state:
> UNCHALLENGED
> 2021/03/24 12:40:30:811 MEZ [DEBUG] MainClientExec - Proxy auth state:
> UNCHALLENGED
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >> POST
> /Testservlet/echoTest HTTP/1.1
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >>
> Content-Length: 23
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >>
> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >> Host:
> localhost:8080
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >> Connection:
> Keep-Alive
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >> User-Agent:
> Apache-HttpClient/4.5.13 (Java/1.8.0)
> 2021/03/24 12:40:30:811 MEZ [DEBUG] headers - http-outgoing-0 >>
> Accept-Encoding: gzip,deflate
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >> "POST
> /Testservlet/echoTest HTTP/1.1[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >>
> "Content-Length: 23[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >>
> "{color:#ffab00}Content-Type: application/x-www-form-urlencoded;
> charset=UTF-8[\r][\n]{color}"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >> "Host:
> localhost:8080[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >> "Connection:
> Keep-Alive[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >> "User-Agent:
> Apache-HttpClient/4.5.13 (Java/1.8.0)[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >>
> "Accept-Encoding: gzip,deflate[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >> "[\r][\n]"
> 2021/03/24 12:40:30:811 MEZ [DEBUG] wire - http-outgoing-0 >>
> {color:#ffab00}"echotext=TEST%C3%B6TEST{color}"
> 2021/03/24 12:40:30:826 MEZ [DEBUG] wire - http-outgoing-0 << "HTTP/1.1 200
> [\r][\n]"
> 2021/03/24 12:40:30:826 MEZ [DEBUG] wire - http-outgoing-0 << "Content-Type:
> application/json;charset=UTF-8[\r][\n]"
> 2021/03/24 12:40:30:826 MEZ [DEBUG] wire - http-outgoing-0 <<
> "Transfer-Encoding: chunked[\r][\n]"
> 2021/03/24 12:40:30:826 MEZ [DEBUG] wire - http-outgoing-0 << "Date: Wed, 24
> Mar 2021 11:40:30 GMT[\r][\n]"
> 2021/03/24 12:40:30:826 MEZ [DEBUG] wire - http-outgoing-0 << "Keep-Alive:
> timeout=20[\r][\n]"
> {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]