[ https://issues.apache.org/jira/browse/HTTPCLIENT-2342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17883346#comment-17883346 ]
Cedric Tabin edited comment on HTTPCLIENT-2342 at 9/20/24 4:44 PM: ------------------------------------------------------------------- Hello, So now we are correctly using the `getContentType()` on the entity but that doesn't change the behaviour. I use now the following code snipped to ensure there is no other strange things going on: {code:java} try(CloseableHttpClient client = HttpClients.createDefault()) { HttpGet get = new HttpGet("http://localhost:9090/help/all/index.html"); get.addHeader("Authorization", "Basic <encoded>"); String contentType = client.execute(get, r -> r.getEntity().getContentType()); assertNotNull(contentType); } {code} The test fails with the version 5.4, but succeeds with the version 5.3.1. So I extracted the debug logs and made the following diff: {code:diff} --- version-5.3.1.txt 2024-09-20 18:27:26.847592754 +0200 +++ version-5.4.txt 2024-09-20 18:27:36.703493996 +0200 @@ -1,30 +1,32 @@ FINE [org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute] ex-0000000001 preparing request execution FINE [org.apache.hc.client5.http.impl.classic.ProtocolExec.execute] ex-0000000001 proxy auth state: UNCHALLENGED -FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 acquiring connection with route {}->http://localhos -t:9090 +FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 acquiring connection with route {}->[http://localho +st:9090] FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint] ex-0000000001 acquiring endpoint (3 MINUTES) FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.lease] ex-0000000001 endpoint lease request (3 MINUTES) -[route: {}->http://localhost:9090][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25] -FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 endpoint leased [route: {}->http:// -localhost:9090][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25] +[route: {}->[http://localhost:9090]][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25] +FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 endpoint leased [route: {}->[http:/ +/localhost:9090]][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25] FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 acquired ep-0000000001 FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint] ex-0000000001 acquired endpoint ep-0000000001 -FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 opening connection {}->http://localhost:9090 +FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 opening connection {}->[http://localhost:9090] FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint] ep-0000000001 connecting endpoint (null) FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect] ep-0000000001 connecting endpoint to http://loc alhost:9090 (3 MINUTES) FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost resolving remote address FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost resolved to [localhost/127.0.0.1, lo calhost/0:0:0:0:0:0:0:1] -FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost:9090 connecting null->localhost/127. -0.0.1:9090 (3 MINUTES) +FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] http://localhost:9090 connecting null->localho +st/127.0.0.1:9090 (3 MINUTES) +FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] http-outgoing-0 http://localhost:9090 connecte +d /127.0.0.1:37462->localhost/127.0.0.1:9090 FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.setSocketTimeout] http-outgoing-0 set socket timeout to 3 MINUTES -FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost:9090 connected null->localhost/127.0 -.0.1:9090 as http-outgoing-0 FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect] ep-0000000001 connected http-outgoing-0 FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint] ep-0000000001 endpoint connected FINE [org.apache.hc.client5.http.impl.classic.MainClientExec.execute] ex-0000000001 executing GET /help/all/index.html HTTP/1.1 +FINE [org.apache.hc.client5.http.protocol.RequestUpgrade.process] Connection is upgradable: protocol version = HTTP/1.1 +FINE [org.apache.hc.client5.http.protocol.RequestUpgrade.process] Connection is upgradable to TLS: method = GET FINE [org.apache.hc.client5.http.protocol.RequestAddCookies.process] ex-0000000001 Cookie spec selected: strict FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.execute] ep-0000000001 start execution ex-0000000001 FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$InternalConnectionEndpoint.execute] ep-0000000001 execut @@ -40,13 +42,18 @@ FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Connection: keep- alive FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> User-Agent: Apach -e-HttpClient/5.3.1 (Java/21.0.4) +e-HttpClient/5.4 (Java/21.0.4) +FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Upgrade: TLS/1.2 +FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Connection: Upgra +de FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "GET /help/all/index.html HTTP/1.1[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Authorization: Basic <basic>[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Accept-Encoding: gzip, x-gzip, deflate[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Host: localhost:9090[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Connection: keep-alive[\r][\n]" -FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.4)[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "User-Agent: Apache-HttpClient/5.4 (Java/21.0.4)[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Upgrade: TLS/1.2[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Connection: Upgrade[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Server: myserver[\r][\n]" @@ -58,6 +65,5 @@ FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Location: /help/all/index.html[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Cache-Control: max-age=86400[\r][\n]" -FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Type: text/html;charset=UTF-8[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Length: 47082[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "X-Frame-Options: SAMEORIGIN[\r][\n]" {code} So we can see something strange with that "Upgrading to TLS 1.2" regardless with the http scheme. Then it seems that the server does not give back the Content-Type according to the logs, but I don't see any reason why it would remove this header in any case... was (Author: ctabin): Hello, So now we are correctly using the `getContentType()` on the entity but that doesn't change the behaviour. I use now the following code snipped to ensure there is no other strange things going on: {code:java} try(CloseableHttpClient client = HttpClients.createDefault()) { HttpGet get = new HttpGet("http://localhost:9090/help/all/index.html"); get.addHeader("Authorization", "Basic <encoded>"); String contentType = client.execute(get, r -> r.getEntity().getContentType()); assertNotNull(contentType); } {code} The test fails with the version 5.4, but succeeds with the version 5.3.1. So I extracted the debug logs and made the following diff: {code:diff} --- version-5.3.1.txt 2024-09-20 18:27:26.847592754 +0200 +++ version-5.4.txt 2024-09-20 18:27:36.703493996 +0200 @@ -1,30 +1,32 @@ FINE [org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute] ex-0000000001 preparing request execution FINE [org.apache.hc.client5.http.impl.classic.ProtocolExec.execute] ex-0000000001 proxy auth state: UNCHALLENGED -FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 acquiring connection with route {}->http://localhos -t:9090 +FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 acquiring connection with route {}->[http://localho +st:9090] FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint] ex-0000000001 acquiring endpoint (3 MINUTES) FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.lease] ex-0000000001 endpoint lease request (3 MINUTES) -[route: {}->http://localhost:9090][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25] -FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 endpoint leased [route: {}->http:// -localhost:9090][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25] +[route: {}->[http://localhost:9090]][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25] +FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 endpoint leased [route: {}->[http:/ +/localhost:9090]][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25] FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$3.get] ex-0000000001 acquired ep-0000000001 FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint] ex-0000000001 acquired endpoint ep-0000000001 -FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 opening connection {}->http://localhost:9090 +FINE [org.apache.hc.client5.http.impl.classic.ConnectExec.execute] ex-0000000001 opening connection {}->[http://localhost:9090] FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint] ep-0000000001 connecting endpoint (null) FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect] ep-0000000001 connecting endpoint to http://loc alhost:9090 (3 MINUTES) FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost resolving remote address FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost resolved to [localhost/127.0.0.1, lo calhost/0:0:0:0:0:0:0:1] -FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost:9090 connecting null->localhost/127. -0.0.1:9090 (3 MINUTES) +FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] http://localhost:9090 connecting null->localho +st/127.0.0.1:9090 (3 MINUTES) +FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] http-outgoing-0 http://localhost:9090 connecte +d /127.0.0.1:37462->localhost/127.0.0.1:9090 FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.setSocketTimeout] http-outgoing-0 set socket timeout to 3 MINUTES -FINE [org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect] localhost:9090 connected null->localhost/127.0 -.0.1:9090 as http-outgoing-0 FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect] ep-0000000001 connected http-outgoing-0 FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint] ep-0000000001 endpoint connected FINE [org.apache.hc.client5.http.impl.classic.MainClientExec.execute] ex-0000000001 executing GET /help/all/index.html HTTP/1.1 +FINE [org.apache.hc.client5.http.protocol.RequestUpgrade.process] Connection is upgradable: protocol version = HTTP/1.1 +FINE [org.apache.hc.client5.http.protocol.RequestUpgrade.process] Connection is upgradable to TLS: method = GET FINE [org.apache.hc.client5.http.protocol.RequestAddCookies.process] ex-0000000001 Cookie spec selected: strict FINE [org.apache.hc.client5.http.impl.classic.InternalExecRuntime.execute] ep-0000000001 start execution ex-0000000001 FINE [org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$InternalConnectionEndpoint.execute] ep-0000000001 execut @@ -40,13 +42,18 @@ FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Connection: keep- alive FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> User-Agent: Apach -e-HttpClient/5.3.1 (Java/21.0.4) +e-HttpClient/5.4 (Java/21.0.4) +FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Upgrade: TLS/1.2 +FINE [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection.onRequestSubmitted] http-outgoing-0 >> Connection: Upgra +de FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "GET /help/all/index.html HTTP/1.1[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Authorization: Basic <basic>[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Accept-Encoding: gzip, x-gzip, deflate[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Host: localhost:9090[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Connection: keep-alive[\r][\n]" -FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.4)[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "User-Agent: Apache-HttpClient/5.4 (Java/21.0.4)[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Upgrade: TLS/1.2[\r][\n]" +FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "Connection: Upgrade[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 >> "[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Server: SAINETV4[\r][\n]" @@ -58,6 +65,5 @@ FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Location: /help/all/index.html[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Cache-Control: max-age=86400[\r][\n]" -FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Type: text/html;charset=UTF-8[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "Content-Length: 47082[\r][\n]" FINE [org.apache.hc.client5.http.impl.Wire.wire] http-outgoing-0 << "X-Frame-Options: SAMEORIGIN[\r][\n]" {code} So we can see something strange with that "Upgrading to TLS 1.2" regardless with the http scheme. Then it seems that the server does not give back the Content-Type according to the logs, but I don't see any reason why it would remove this header in any case... > Regression: Content-Type header not returned anymore > ---------------------------------------------------- > > Key: HTTPCLIENT-2342 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2342 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) > Affects Versions: 5.4-beta1 > Reporter: Cedric Tabin > Priority: Major > > Hello, > We just upgraded today to httpclient5 version 5.4. It seems that the header > `Content-Type` is not returned anymore by the API, even when listing all the > headers. > {code:java} > client.execute(httpRequest, r -> { > //does not print Content-Type header > for(Header h : r.getHeaders()) { > System.out.println("## "+h.getName()+": "+h.getValue()); > } > System.out.flush(); > return null; > }); > {code} > We can ensure that the `Content-Type` header is well set by the server by > browsing to the same URL and inspecting the network. > Our code didn't change and with the version 5.3.1, the Content-Type is > correctly received. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org