]> Cypherpunks repositories - gostls13.git/commit
net/http: handle body rewind in HTTP/2 connection loss better
authorRuss Cox <rsc@golang.org>
Fri, 22 May 2020 00:46:05 +0000 (20:46 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 27 May 2020 16:56:56 +0000 (16:56 +0000)
commite3491c46034cecbaf0f33928b09e1e3c0c6a0d20
tree2f034145771fda8e0d350a8eb096246950be30c4
parent748533e3a1a8e64b3910b9cac1e767d95ee38f84
net/http: handle body rewind in HTTP/2 connection loss better

In certain cases the HTTP/2 stack needs to resend a request.
It obtains a fresh body to send by calling req.GetBody.
This call was missing from the path where the HTTP/2
round tripper returns ErrSkipAltProtocol, meaning fall back
to HTTP/1.1. The result was that the HTTP/1.1 fallback
request was sent with no body at all.

This CL changes that code path to rewind the body before
falling back to HTTP/1.1. But rewinding the body is easier
said than done. Some requests have no GetBody function,
meaning the body can't be rewound. If we need to rewind and
can't, that's an error. But if we didn't read anything, we don't
need to rewind. So we have to track whether we read anything,
with a new ReadCloser wrapper. That in turn requires adding
to the couple places that unwrap Body values to look at the
underlying implementation.

This CL adds the new rewinding code in the main retry loop
as well.

The new rewindBody function also takes care of closing the
old body before abandoning it. That was missing in the old
rewind code.

Thanks to Aleksandr Razumov for CL 210123
and to Jun Chen for CL 234358, both of which informed
this CL.

Fixes #32441.

Change-Id: Id183758526c087c6b179ab73cf3b61ed23a2a46a
Reviewed-on: https://go-review.googlesource.com/c/go/+/234894
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/net/http/transfer.go
src/net/http/transport.go
src/net/http/transport_test.go