http3: don't modify any fields of the http.Request when doing 0-RTT (#4379)

This commit is contained in:
Marten Seemann
2024-03-24 06:58:41 +10:00
committed by GitHub
parent 603e07779a
commit 684b80a23f
2 changed files with 8 additions and 0 deletions

View File

@@ -305,8 +305,14 @@ func (c *client) roundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Respon
// Immediately send out this request, if this is a 0-RTT request.
switch req.Method {
case MethodGet0RTT:
// don't modify the original request
reqCopy := *req
req = &reqCopy
req.Method = http.MethodGet
case MethodHead0RTT:
// don't modify the original request
reqCopy := *req
req = &reqCopy
req.Method = http.MethodHead
default:
// wait for the handshake to complete

View File

@@ -824,6 +824,8 @@ var _ = Describe("Client", func() {
_, err := cl.RoundTripOpt(req, RoundTripOpt{})
Expect(err).To(MatchError(testErr))
Expect(decodeHeader(buf)).To(HaveKeyWithValue(":method", serialized))
// make sure the request wasn't modified
Expect(req.Method).To(Equal(method))
},
Entry("GET", MethodGet0RTT, http.MethodGet),
Entry("HEAD", MethodHead0RTT, http.MethodHead),