• Brad Fitzpatrick's avatar
    net/http: reuse HTTP/1 Transport conns more for gzipped responses · 18072adb
    Brad Fitzpatrick authored
    Flip around the composition order of the http.Response.Body's
    gzip.Reader vs. the reader which keeps track of waiting to see the end
    of the HTTP/1 response framing (whether that's a Content-Length or
    HTTP/1.1 chunking).
    
    Previously:
    
    user -> http.Response.Body
         -> bodyEOFSignal
         -> gzipReader
         -> gzip.Reader
         -> bufio.Reader
       [ -> http/1.1 de-chunking reader ]   optional
         -> http1 framing *body
    
    But because bodyEOFSignal was waiting to see an EOF from the
    underlying gzip.Reader before reusing the connection, and gzip.Reader
    (or more specifically: the flate.Reader) wasn't returning an early
    io.EOF with the final chunk, the bodyEOfSignal was never releasing the
    connection, because the EOF from the http1 framing was read by a party
    who didn't care about it yet: the helper bufio.Reader created to do
    byte-at-a-time reading in the flate.Reader.
    
    Flip the read composition around to:
    
    user -> http.Response.Body
         -> gzipReader
         -> gzip.Reader
         -> bufio.Reader
         -> bodyEOFSignal
       [ -> http/1.1 de-chunking reader ]   optional
         -> http1 framing *body
    
    Now when gzip.Reader does its byte-at-a-time reading via the
    bufio.Reader, the bufio.Reader will do its big reads against the
    bodyEOFSignal reader instead, which will then see the underlying http1
    framing EOF, and be able to reuse the connection.
    
    Updates google/go-github#317
    Updates #14867
    And related abandoned fix to flate.Reader: https://golang.org/cl/21290
    
    Change-Id: I3729dfdffe832ad943b84f4734b0f59b0e834749
    Reviewed-on: https://go-review.googlesource.com/21291Reviewed-by: 's avatarDavid Symonds <dsymonds@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    18072adb
Name
Last commit
Last update
..
cgi Loading commit data...
cookiejar Loading commit data...
fcgi Loading commit data...
httptest Loading commit data...
httputil Loading commit data...
internal Loading commit data...
pprof Loading commit data...
testdata Loading commit data...
client.go Loading commit data...
client_test.go Loading commit data...
clientserver_test.go Loading commit data...
cookie.go Loading commit data...
cookie_test.go Loading commit data...
doc.go Loading commit data...
example_test.go Loading commit data...
export_test.go Loading commit data...
filetransport.go Loading commit data...
filetransport_test.go Loading commit data...
fs.go Loading commit data...
fs_test.go Loading commit data...
h2_bundle.go Loading commit data...
header.go Loading commit data...
header_test.go Loading commit data...
http_test.go Loading commit data...
jar.go Loading commit data...
lex.go Loading commit data...
lex_test.go Loading commit data...
main_test.go Loading commit data...
method.go Loading commit data...
npn_test.go Loading commit data...
proxy_test.go Loading commit data...
race.go Loading commit data...
range_test.go Loading commit data...
readrequest_test.go Loading commit data...
request.go Loading commit data...
request_test.go Loading commit data...
requestwrite_test.go Loading commit data...
response.go Loading commit data...
response_test.go Loading commit data...
responsewrite_test.go Loading commit data...
serve_test.go Loading commit data...
server.go Loading commit data...
sniff.go Loading commit data...
sniff_test.go Loading commit data...
status.go Loading commit data...
transfer.go Loading commit data...
transfer_test.go Loading commit data...
transport.go Loading commit data...
transport_test.go Loading commit data...
triv.go Loading commit data...