[
https://issues.apache.org/jira/browse/HTTPCLIENT-2176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17412845#comment-17412845
]
Michael Osipov commented on HTTPCLIENT-2176:
--------------------------------------------
The behavior of the HttpClient is correct:
{noformat}
$ curl -H "Accept-Encoding: deflate, gzip"
"https://direitosculturais.com.br/pdf.php?id=151" --verbose --http1.1 > file
* Uses proxy env variable NO_PROXY == 'localhost .siemens.net .siemens.com
.siemens.de'
* Uses proxy env variable HTTPS_PROXY == 'http://de.coia.siemens.net:9400'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0*
Trying 194.145.60.253:9400...
* Connected to de.coia.siemens.net (194.145.60.253) port 9400 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to direitosculturais.com.br:443
> CONNECT direitosculturais.com.br:443 HTTP/1.1
> Host: direitosculturais.com.br:443
> User-Agent: curl/7.78.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection Established
< Proxy-Agent: Zscaler/6.1
<
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: none
* CApath: /etc/ssl/certs/
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [108 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4066 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: CN=direitosculturais.com.br
* start date: Jul 14 22:29:23 2021 GMT
* expire date: Oct 12 22:29:22 2021 GMT
* subjectAltName: host "direitosculturais.com.br" matched cert's
"direitosculturais.com.br"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
} [5 bytes data]
> GET /pdf.php?id=151 HTTP/1.1
> Host: direitosculturais.com.br
> User-Agent: curl/7.78.0
> Accept: */*
> Accept-Encoding: deflate, gzip
>
{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 09 Sep 2021 21:09:13 GMT
< Server: Apache
< Content-Disposition: attachment; filename=PATRIMONIOS_CULTURAIS_E_PANDEMIA.pdf
< Content-Transfer-Encoding: binary
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Upgrade: h2
< Connection: Upgrade
< Content-Length: 216481
< Content-Type: application/save
<
0 211k 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{
[5 bytes data]
94 211k 94 199k 0 0 34804 0 0:00:06 0:00:05 0:00:01 34805*
TLSv1.2 (IN), TLS alert, close notify (256):
{ [2 bytes data]
* transfer closed with 12661 bytes remaining to read
94 211k 94 199k 0 0 32259 0 0:00:06 0:00:06 --:--:-- 37660
* Closing connection 0
} [5 bytes data]
* TLSv1.2 (OUT), TLS alert, close notify (256):
} [2 bytes data]
curl: (18) transfer closed with 12661 bytes remaining to read
osipovmi@deblndw011x:~
$ ll file
-rw-r--r-- 1 osipovmi cad 203820 2021-09-09 23:09 file
{noformat}
Since the client requests content compression the content length applies to the
compressed content and not the expanded one. In fact, the server should
actually use chunked encoding with content encoding to avoid such issues.
For me, the server is misconfigured.
> Premature end of Content-Length delimited message body but works with wget
> --------------------------------------------------------------------------
>
> Key: HTTPCLIENT-2176
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2176
> Project: HttpComponents HttpClient
> Issue Type: Task
> Components: HttpClient (classic)
> Affects Versions: 4.5.13
> Environment: httpclient: 4.5.13
> httpcore: 4.4.14
> java 11 (archaic): openjdk version "11.0.4" 2019-07-16
> Reporter: Tim Allison
> Priority: Minor
>
> I'm doing a recrawl of truncated files from CommonCrawl in support of work on
> Apache Tika, and I've found a few files where I'm able to download the files
> successfully with wget but with httpclient, I'm getting:
> {noformat}
> org.apache.http.ConnectionClosedException: Premature end of Content-Length
> delimited message body (expected: 216,481; received: 203,820)
> at
> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
> at
> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:198)
> at
> org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:101)
> at
> org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
> at
> org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
> at
> org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
> at
> java.base/java.util.zip.InflaterInputStream.close(InflaterInputStream.java:232)
> at
> java.base/java.util.zip.GZIPInputStream.close(GZIPInputStream.java:137)
> at
> org.apache.http.client.entity.LazyDecompressingInputStream.close(LazyDecompressingInputStream.java:94)
> at FetcherTest.testBasic(FetcherTest.java:40)
>
> {noformat}
> The triggering file is: https://direitosculturais.com.br/pdf.php?id=151
> Example all defaults:
> {noformat}
> String url = "https://direitosculturais.com.br/pdf.php?id=151";
> HttpClient client = HttpClientBuilder.create().build();
> HttpGet get = new HttpGet(url);
> HttpResponse r = client.execute(get);
> Path output = Paths.get("/data/tmp.pdf");
> try (InputStream is = r.getEntity().getContent()) {
> Files.copy(is, output, StandardCopyOption.REPLACE_EXISTING);
> }
> {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]