]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.16] net/http: fix ResponseWriter.ReadFrom with short reads
authorDamien Neil <dneil@google.com>
Fri, 12 Mar 2021 21:53:11 +0000 (13:53 -0800)
committerDmitri Shuralyov <dmitshur@golang.org>
Tue, 29 Jun 2021 17:42:45 +0000 (17:42 +0000)
commitcb4cd9e17753b5cd8ee4cd5b1f23d46241b485f1
treeb411b80c10126a0baade6935bd02cffff10e65ce
parentd4ee0255f26ec755181682133dae0238b690274c
[release-branch.go1.16] net/http: fix ResponseWriter.ReadFrom with short reads

CL 249238 changes ResponseWriter.ReadFrom to probe the source with
a single read of sniffLen bytes before writing the response header.
If the source returns less than sniffLen bytes without reaching
EOF, this can cause Content-Type and Content-Length detection to
fail.

Fix ResponseWrite.ReadFrom to copy a full sniffLen bytes from
the source as a probe.

Drop the explicit call to w.WriteHeader; writing the probe will
trigger a WriteHeader call.

Consistently use io.CopyBuffer; ReadFrom has already acquired a
copy buffer, so it may as well use it.

Fixes #44984.
Updates #44953.

Change-Id: Ic49305fb827a2bd7da4764b68d64b797b5157dc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/301449
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
(cherry picked from commit 831f9376d8d730b16fb33dfd775618dffe13ce7a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/324971
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/net/http/server.go
src/net/http/sniff_test.go