Rainer Jung created HTTPCLIENT-1742:
---------------------------------------

             Summary: No connection reuse is respnse is compressed
                 Key: HTTPCLIENT-1742
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1742
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.5.2
         Environment: Linux, Java 8
            Reporter: Rainer Jung


Trying current JMeter trunk I ran into a problem, that connections were not 
being reused. Debugging into it revealed IMHO a HttpClient/HttpCore problem.

Below you'll find a wire dump of the request and the response headers:

2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "HTTP/1.1 200 OK[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Date: Tue, 10 May 2016 
20:44:15 GMT[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Server: Apache[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Pragma: no-cache[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Cache-Control: no-cache, 
no-store, must-revalidate[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Expires: 0[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Pragma: no-cache[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Cache-Control: no-cache, 
no-store, must-revalidate[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Expires: 0[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Pragma: no-cache[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Cache-Control: no-cache, 
no-store, must-revalidate[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Expires: 0[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Vary: 
Accept-Encoding[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Content-Encoding: 
gzip[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "X-Content-Type-Options: 
nosniff[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "X-Frame-Options: 
sameorigin[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Content-Length: 
1194[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Keep-Alive: timeout=60, 
max=9999[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Connection: 
Keep-Alive[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "Content-Type: 
text/html;charset=utf-8[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.wire:  << "[\r][\n]"
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << HTTP/1.1 200 OK
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Date: Tue, 10 May 2016 
20:44:15 GMT
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Server: Apache
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Pragma: no-cache
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Cache-Control: 
no-cache, no-store, must-revalidate
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Expires: 0
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Pragma: no-cache
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Cache-Control: 
no-cache, no-store, must-revalidate
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Expires: 0
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Pragma: no-cache
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Cache-Control: 
no-cache, no-store, must-revalidate
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Expires: 0
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Vary: Accept-Encoding
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Content-Encoding: gzip
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << X-Content-Type-Options: 
nosniff
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << X-Frame-Options: 
sameorigin
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Content-Length: 1194
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Keep-Alive: timeout=60, 
max=9999
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Connection: Keep-Alive
2016/05/10 22:44:15 DEBUG - org.apache.http.headers: << Content-Type: 
text/html;charset=utf-8

As you can see, the response contains a Content-Length header, is not chunked 
but is gzip compressed. The server sets a Connection header keep-alive and 
sends keep-alive values that would let the connection be reused. But instead 
DefaultConnectionReuseStrategy.keepAlive() returns false, because in the code 
block

            if (canResponseHaveBody(response)) {
                final Header[] clhs = response.getHeaders(HTTP.CONTENT_LEN);
                // Do not reuse if not properly content-length delimited
                if (clhs.length == 1) {

the value of clhs.length is 0. So although the wire dump shows a content-length 
header, and the request is not chunked, somewhere the content-length header is 
being removed.

As soon as I remove the "Accept-Encoding: gzip, deflate" request header, 
connections get reused and the content-length header no longer gets removed.

I expect the class ResponseContentEncoding to be responsible: it removes the 
header via

response.removeHeaders("Content-Length");

in line 141.

Regards,

Rainer



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to