664 Commits

Author SHA1 Message Date
Michael Fraenkel
296f09aa38 http2: case insensitive handling for 100-continue
rfc 9110, section 10.1.1 states that the Expect field value is
case-insensitive.

Fixes golang/go#57824

Change-Id: Ie0e2662c58a2933087e0d35935c04ec61026a41d
Reviewed-on: https://go-review.googlesource.com/c/net/+/463096
Auto-Submit: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-26 21:33:21 +00:00
Damien Neil
7805fdc37d http2: rewrite inbound flow control tracking
Add a new inflow type for tracking inbound flow control.
An inflow tracks both the window sent to the peer, and the
window we are willing to send. Updates are accumulated and
sent in a batch when the unsent window update is large
enough.

This change makes both the client and server use the same
algorithm to decide when to send window updates. This should
slightly reduce the rate of updates sent by the client, and
significantly reduce the rate sent by the server.

Fix a client flow control tracking bug: When processing data
for a canceled stream, the record of flow control consumed
by the peer was not updated to account for the discard
stream.

Fixes golang/go#28732
Fixes golang/go#56558

Change-Id: Id119d17b84b46f3dc2719f28a86758d9a10085d9
Reviewed-on: https://go-review.googlesource.com/c/net/+/448155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2023-01-03 19:04:08 +00:00
Dmitri Shuralyov
e1ec361d0b http2: fix race in TestCanonicalHeaderCacheGrowth
As Damien found in the 2nd patch set of CL 455736 and CL 455735,
disableGoroutineTracking is racy (but only called by benchmarks
that don't care); set the serverConn.serveG in the test instead.

Fixes golang/go#57218.

Change-Id: I5e39be3c7fbac93260a26951491863b06b39d672
Reviewed-on: https://go-review.googlesource.com/c/net/+/456523
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-12-10 04:57:30 +00:00
Damien Neil
1e63c2f08a http2: limit canonical header cache by bytes, not entries
The canonical header cache is a per-connection cache mapping header
keys to their canonicalized form. (For example, "foo-bar" => "Foo-Bar").
We limit the number of entries in the cache to prevent an attacker
from consuming unbounded amounts of memory by sending many unique
keys, but a small number of very large keys can still consume an
unreasonable amount of memory.

Track the amount of memory consumed by the cache and limit it based
on memory rather than number of entries.

Thanks to Josselin Costanzi for reporting this issue.

For golang/go#56350

Change-Id: I41db4c9823ed5bf371a9881accddff1268489b16
Reviewed-on: https://go-review.googlesource.com/c/net/+/455635
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-06 20:08:15 +00:00
Damien Neil
ecf7fda6a5 http2: deflake TestTransportMaxFrameReadSize
Rewrite this test to examine the SETTINGS frame sent by the Transport
directly, rather than poking around in the Server internals to find
the sent value.

Fixes golang/go#56806

Change-Id: I47859352a14b7120ef88fce5bd000716b9abdad7
Reviewed-on: https://go-review.googlesource.com/c/net/+/451775
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2022-11-17 21:55:42 +00:00
robaho
2f8c3d16b3 http2: add Transport.MaxReadFrameSize configuration setting
For golang/go#47840.
Fixes golang/go#54850.

Change-Id: I44efec8d1f223b3c2be82a2e11752fbbe8bf2cbf
Reviewed-on: https://go-review.googlesource.com/c/net/+/362834
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
2022-11-15 19:08:01 +00:00
Eli Lindsey
0e478a2a5f http2: add SETTINGS_HEADER_TABLE_SIZE support
Add support for handling of SETTINGS_HEADER_TABLESIZE in SETTINGS
frames.

Add http2.Transport.MaxDecoderHeaderTableSize to set the advertised
table size for new client connections. Add
http2.Transport.MaxEncoderHeaderTableSize to cap the accepted size for
new client connections.

Add http2.Server.MaxDecoderHeaderTableSize and MaxEncoderHeaderTableSize
to do the same on the server.

Fixes golang/go#29356
Fixes golang/go#56054

Change-Id: I16ae0f84b8527dc1e09dfce081e9f408fd514513
Reviewed-on: https://go-review.googlesource.com/c/net/+/435899
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-11-15 00:40:55 +00:00
Damien Neil
15e1b25565 http2: speed up TestTransportRetryHasLimit
This test takes ~30s to execute with real timers, making it almost
50% of the total execution time of the http2 tests. Use a fake
timer in tests.

Change-Id: I750237c7d3b8f7b87881b8a0a8aff2bf4a3cdd9f
Reviewed-on: https://go-review.googlesource.com/c/net/+/446375
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 22:13:06 +00:00
Damien Neil
93ec86b443 http2: support SetReadDeadline, SetWriteDeadline, FlushError
Add support for ResponseController methods to set read/write deadlines
and flush with an error return.

Change-Id: I63059d13bef28dc32a4b8b75901eb1dd56176f32
Reviewed-on: https://go-review.googlesource.com/c/net/+/446335
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2022-11-04 20:05:59 +00:00
Damien Neil
efda1ce189 http2: return os.ErrDeadlineExceeded from timed-out response body writes
When a server handler writes to a response body after Server.WriteTimeout
has expired, return an error matching os.ErrDeadlineExceeded rather than
"http2: stream closed".

Tested by net/http CL 446255.

For golang/go#56478

Change-Id: I94494cc7e7f8f9a01a663de09fd5b73acc8ea4e4
Reviewed-on: https://go-review.googlesource.com/c/net/+/446257
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-04 20:05:49 +00:00
Damien Neil
a870f3529a http2: support Server.ReadTimeout
Return an error when reading from the request body in a server
handler after Server.ReadTimeout expires.

Tested by net/http CL 446255.

For golang/go#49837

Change-Id: Idcc3d92209f944bd7fead832525fd563b50bcebc
Reviewed-on: https://go-review.googlesource.com/c/net/+/446256
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-11-04 20:05:42 +00:00
Damien Neil
d7f77dcacc Revert "http2: Send WindowUpdates when remaining bytes are below a threshold"
This reverts commit 2e0b12c274.

The calculation for when to return flow control doesn't properly take
data in server read buffers into account, resulting in flow control
credit being returned too quickly without backpressure.

Fixes golang/go#56315
For golang/go#28732

Change-Id: I573afd1a37d8a711da47f05f38f4de04183fb941
Reviewed-on: https://go-review.googlesource.com/c/net/+/448055
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-11-04 19:17:55 +00:00
Damien Neil
702349b0e8 http2/h2c: handle errors when reading HTTP/1 request body
When processing an HTTP/1 Upgrade: h2c request, detect errors reading
the request body and fail the request rather than passing off the
partially-read request to the HTTP/2 server.

Correctly handles the case where a MaxBytesHandler has limited the
size of the initial HTTP/1 request body.

Fixes golang/go#56352

Change-Id: I08d60953cea26961cffbab3094cc1b44236f4e37
Reviewed-on: https://go-review.googlesource.com/c/net/+/447396
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: John Howard <howardjohn@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-11-04 16:29:52 +00:00
Nikola Jokic
7a676822c2 x/net/http2: gzipReader will reset zr to nil after closing body
The existing implementation does not reset gz.zr. After Close,
gzipReader closes underlying response body but buffered data can still
be read.

gzipReader on Close sets the gz.zerr to fs.ErrClosed so next Read after
Close will return it immediately.

Fixes golang/go#56020

Change-Id: I8a31e4c65656b9abc3023855b8e04342e1e77cbb
Reviewed-on: https://go-review.googlesource.com/c/net/+/440555
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-11-04 14:56:32 +00:00
Eli Lindsey
a1278a7f7e http2: add common header caching to Transport to reduce allocations
Currently Server builds two process-global maps to cut down allocations
due to lower-casing and canonicalization of common headers.

Lower-casing/canonicalization has also been a significant source of
garbage in Transport - this change extends use of the same
process-global maps to the client.

Change-Id: I2324c9567a61f28d4dd633a2c0618f08ddbf457c
Reviewed-on: https://go-review.googlesource.com/c/net/+/442175
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-02 18:17:56 +00:00
Eli Lindsey
c877839975 http2: add a few other common headers to the shared headermap cache
This change adds additional common CORS headers and two de-facto
standard and common X- headers to the shared headermap cache to cut down
on allocations from lower-casing/canonicalization.

Change-Id: I61121925b0b28414ed6ce07190155662b0444f93
Reviewed-on: https://go-review.googlesource.com/c/net/+/442176
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-11-01 21:01:22 +00:00
Damien Neil
c63010009c http2: discard more frames after GOAWAY
After sending a GOAWAY with NO_ERROR, we should discard all frames
for streams with larger identifiers than the last stream identifier
in the GOAWAY frame. We weren't discarding RST_STREAM frames, which
could cause us to incorrectly detect a protocol error when handling
a RST_STREAM for a discarded stream.

Hoist post-GOAWAY frame discarding higher in the loop rather than
handling it on a per-frame-type basis.

We are also supposed to count discarded DATA frames against
connection-level flow control, possibly sending WINDOW_UPDATE
messages to return the flow control. We weren't doing this;
this is now fixed.

Fixes golang/go#55846

Change-Id: I7603a529c00b8637e648eee9cc4608fb5fa5199b
Reviewed-on: https://go-review.googlesource.com/c/net/+/434909
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: LI ZHEN <mr.imuz@gmail.com>
Reviewed-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
2022-10-27 16:40:07 +00:00
Zeke Lu
0c1aede73a http2: calculate a correct window increment size for a stream
CL 432038 reduces sending WindowUpdates by introducing a threshold. Once
the remaining bytes are below the threshold, a single WindowUpdate is
sent to reset the amount back to the maximum amount configured.

The window increment size for a stream is calculated from:

    sc.srv.initialStreamRecvWindowSize() - st.inflow.available()

Where (*flow).available is defined as:

    func (f *flow) available() int32 {
    	n := f.n
    	if f.conn != nil && f.conn.n < n {
    		n = f.conn.n
    	}
    	return n
    }

When f.conn.c < f.n, it gets a bigger increment size. It should be
calculated from:

    sc.srv.initialStreamRecvWindowSize() - st.inflow.n

While we're here, remove an unnecessary type conversion too.

Updates golang/go#56315.

Change-Id: I4b26b27e4c5c5cd66e6a32b152d68f304adc65d8
GitHub-Last-Rev: 02fc09c1e7
GitHub-Pull-Request: golang/net#155
Reviewed-on: https://go-review.googlesource.com/c/net/+/444816
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2022-10-27 04:30:12 +00:00
Tomasz Jezierski
84c13af5f4 http2/hpack: build static table with go generate
As the static version of headerFieldTable in hpack is generated in runtime,
we may use the go:generate to prepare the struct before the initialization phase.
This is supposed to save init time and allocations for many binaries,
as net/http imports hpack.

Before:
init golang.org/x/net/http2/hpack @1.1 ms, 0.097 ms clock, 21240 bytes, 29 allocs
After:
init golang.org/x/net/http2/hpack @0.67 ms, 0.015 ms clock, 8120 bytes, 9 allocs

Fixes golang/go#55881

Change-Id: Ia6575f67ffcba7cc4d75899b24a9c56deb58ccac
Reviewed-on: https://go-review.googlesource.com/c/net/+/434875
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-27 00:09:11 +00:00
ChristLZS
da05058a03 net/http: remove unnecessary slicing
Change-Id: Ie7248c9e7f60c121e6137f28803c8fa2709f2d92
Reviewed-on: https://go-review.googlesource.com/c/net/+/444395
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-20 15:09:23 +00:00
hopehook
bcab684115 all: use time.Since instead of time.Now().Sub
Change-Id: Ie6ab0d9b0933f8c0dda84e7f8ad879e01c4eb337
Reviewed-on: https://go-review.googlesource.com/c/net/+/437095
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-10-02 02:25:38 +00:00
Damien Neil
107f3e3c3b http2: don't return from RoundTrip until request body is closed
Moving the Request.Body.Close call out from the ClientConn mutex
results in some cases where RoundTrip returns while the Close is
still in progress. This should be legal (RoundTrip explicitly allows
for this), but net/http relies on Close never being called after
RoundTrip returns.

Add additional synchronization to ensure Close calls complete
before RoundTrip returns.

Fixes golang/go#55896

Change-Id: Ie3d4773966745e83987d219927929cb56ec1a7ad
Reviewed-on: https://go-review.googlesource.com/c/net/+/435535
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-30 21:31:12 +00:00
Nikola Jokic
f486391704 http2: improved Request.Body.Close not to hold lock on connection
The existing implementation holds a lock on a connection which causes
issues on a slow Request.Body.Close call.

Unlock before Request.Body.Close call. The abortStream closes the request
body after unlocking a mutex. The abortStreamLocked returns reqBody as
io.ReadCloser if the caller needs to close the body after unlocking the
mutex.

Fixes golang/go#52853

Change-Id: I0b74ba5263f65393c0e69e1c645d10c4db048903
Reviewed-on: https://go-review.googlesource.com/c/net/+/424755
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-27 17:12:03 +00:00
Damien Neil
aa73b25870 http2: handle MaxUploadBufferPerConnection of 65535
Fix a fencepost error causing us to ignore a
Server.MaxUploadBufferPerConnection value of 65535 (the minimum).

Change-Id: Ibca0347576c360cfa4fe841c05b23afe165b96e0
Reviewed-on: https://go-review.googlesource.com/c/net/+/434913
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-27 15:52:33 +00:00
Damien Neil
d300de134e http2: don't rely on double-close of a net.Conn failing
The js_wasm net.Conn implementation doesn't return an error on
double-closing a connection. Update tests to not rely on this
behavior.

Change-Id: I674c6cd6364b7351d627626cf5bd9f59b3c2b96c
Reviewed-on: https://go-review.googlesource.com/c/net/+/432515
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-21 20:36:46 +00:00
Michael Fraenkel
db77216a4e http2: remove race from TestTransportCancelDataResponseRace
Wait for the client request to return before cancelling the request.
Then cancel the request and send more data.

Fixes: golang/go#45701

Change-Id: Icc81f9c6fefdda1d978e6234c9894f552daecd45
Reviewed-on: https://go-review.googlesource.com/c/net/+/320369
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-09-21 15:50:15 +00:00
Damien Neil
d0c6ba3f52 http2: close client connections after receiving GOAWAY
Once a connection has received a GOAWAY from the server,
close it after the last outstanding request on the connection
completes.

We're lax about when we call ClientConn.closeConn, frequently
closing the underlying net.Conn multiple times. Stop propagating
errors on closing the net.Conn up through ClientConn.Close and
ClientConn.Shutdown, since these errors are likely to be caused
by double-closing the connection rather than a real fault.

Fixes golang/go#39752.

Change-Id: I06d59e6daa6331c3091e1d49cdbeac313f17e6bd
Reviewed-on: https://go-review.googlesource.com/c/net/+/429060
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2022-09-20 20:31:00 +00:00
Damien Neil
2e0b12c274 http2: Send WindowUpdates when remaining bytes are below a threshold
This rolls-forward CL 150197 with an added fix for
TestProtocolErrorAfterGoAway.

Rather than send a WindowUpdate on every chunk of bytes read, allow them
to collect until we go past half the configured window size. Once the
threshold is reached, send a single WindowUpdate to reset the amount
back to the maximum amount configured.

Fixes golang/go#28732

Change-Id: Icee93dedf68d6166aa6fe0c3845d717e66586e73
Reviewed-on: https://go-review.googlesource.com/c/net/+/432038
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
2022-09-20 19:17:52 +00:00
Damien Neil
bf014ff85a http2: send undeclared trailers when body is not written
Fix a bug wherein undeclared trailers (set with the "Trailer:" prefix)
were not sent when the response body is neither written nor flushed.

We were testing responseWriterState.hasTrailers before promoting
undeclared trailers into rws.trailers, resulting in the response headers
being sent with an END_STREAM flag. Promote undeclared headers earlier
so that we leave the stream open for them to be sent.

For golang/go#54723

Change-Id: Ic036925f4a7ec775282b6e474aa72249d6418b23
Reviewed-on: https://go-review.googlesource.com/c/net/+/426874
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-09-20 18:38:52 +00:00
Damien Neil
4a395b0a80 Revert "http2: Send WindowUpdates when remaining bytes are below a threshold"
This reverts commit f2f64ebce3.

Reason for revert: failing builders

Change-Id: I6cbe30f9de4aa19f8a7aed939fc94f8e687673f0
Reviewed-on: https://go-review.googlesource.com/c/net/+/432037
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-20 15:27:17 +00:00
Michael Fraenkel
f2f64ebce3 http2: Send WindowUpdates when remaining bytes are below a threshold
Rather than send a WindowUpdate on every chunk of bytes read, allow them
to collect until we go past half the configured window size. Once the
threshold is reached, send a single WindowUpdate to reset the amount
back to the maximum amount configured.

Fixes golang/go#28732

Change-Id: I177f962ee0a9b8daa1c4817e0ab7698e828bad96
Reviewed-on: https://go-review.googlesource.com/c/net/+/150197
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2022-09-19 23:24:10 +00:00
Weidi Deng
0081b4bacc http2/h2c: propagate HTTP/1 server configuration to HTTP/2
Fixes golang/go#37089

Change-Id: I793bf8b420fd7b5a47b45ad1521c5b5f9e0321b2
GitHub-Last-Rev: 805b90e36a
GitHub-Pull-Request: golang/net#139
Reviewed-on: https://go-review.googlesource.com/c/net/+/419181
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-09-19 22:51:23 +00:00
Damien Neil
f8f703f979 http2: accept HEAD requests with a body
RFC 7231 permits HEAD requests to contain a body, although it does
state there are no defined semantics for payloads of HEAD requests
and that some servers may reject HEAD requests with a payload.

Accept HEAD requests with a body.

Test is in net/http CL 418614.

For golang/go#53960.

Change-Id: I946d3ec796054c3908beb8a69cc78aa51c04c972
Reviewed-on: https://go-review.googlesource.com/c/net/+/418634
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-09-19 17:16:27 +00:00
Damien Neil
f3363e06e7 http2: handle server errors after sending GOAWAY
The HTTP/2 server uses serverConn.goAwayCode to track whether a
connection has encountered a fatal error. If an error is encountered
after sending a ErrCodeNo GOAWAY, upgrade goAwayCode to reflect the
error status of the connection.

Fixes an issue where a server connection could hang forever waiting
for a clean shutdown that was preempted by a subsequent fatal error.

Fixes CVE-2022-27664
For golang/go#53977

Change-Id: I165b81ab53176c77a68c42976030499d57bb05d3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1413887
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/net/+/428735
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-06 16:51:46 +00:00
Damien Neil
4c34ddd1e7 http2: delete multipart form tempfiles after ServeHTTP returns
Do the same post-handler cleanup as the HTTP/1 server does.
No test here; test for HTTP/1 and HTTP/2 in CL 423194.

For golang/go#20253.

Change-Id: Iba54110ad2844571076c721d7ec19c39ba36de79
Reviewed-on: https://go-review.googlesource.com/c/net/+/423055
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2022-08-12 17:26:08 +00:00
Dreamacro
1d4ff48094 http2: add DialTLSContext to Transport
Fixes golang/go#52114

Change-Id: Ibc0ba6b401bb39ea89f88796d55fbf781596140e
GitHub-Last-Rev: 488673bebe
GitHub-Pull-Request: golang/net#123
Reviewed-on: https://go-review.googlesource.com/c/net/+/377114
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-08-12 16:54:38 +00:00
Ronak Jain
13a9a731de http2: fix conn flow control when stream closes on bad content-length
HTTP2 server does not send WINDOW_UPDATE when the client
sends more data than declared in the content-length header.

Client flow control can eventually run out of available bytes which
hangs the client connection as it cannot write DATA frames for any
stream any longer.

Fixes: golang/go#54185

Change-Id: I48ae3212fb31ce302715abe129adf5c9625faf12
GitHub-Last-Rev: 1351d3b416
GitHub-Pull-Request: golang/net#143
Reviewed-on: https://go-review.googlesource.com/c/net/+/421974
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-11 18:24:39 +00:00
Ronak Jain
0bcc04d9c6 http2: fix spec document links
Spec documents are no longer available on https://http2.github.io,
they are available at https://httpwg.org/specs.

Change-Id: Ifc2326ac381e59c00149c4b17738faa4837eec63
GitHub-Last-Rev: fbda1b49c2
GitHub-Pull-Request: golang/net#141
Reviewed-on: https://go-review.googlesource.com/c/net/+/420616
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-08-02 22:28:14 +00:00
Maxime Veber
c90051bbdb http2/h2i: update install documentation
Change "go get" to "go install".

Change-Id: Ie62a4a24dfbfc53208df05845d03e64845eb41da
GitHub-Last-Rev: e1f9aef7b7
GitHub-Pull-Request: golang/net#138
Reviewed-on: https://go-review.googlesource.com/c/net/+/416015
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-07-06 16:39:47 +00:00
Bryan Mills
9d032be2e5 Revert "http2: enable VerboseLogs in TestTransportGroupsPendingDials"
This reverts CL 411294.

Reason for revert: introduced a data race due to a goroutine left in flight by some other test.

Fixes golang/go#53480.

Change-Id: Ib31b61e7a8eb95dfa585283b7f61bb829916e9dd
Reviewed-on: https://go-review.googlesource.com/c/net/+/413397
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-06-21 19:30:19 +00:00
Damien Neil
355a448f1b http2: enable VerboseLogs in TestTransportGroupsPendingDials
This test is very, very rarely flaky. Enable additional logs to help
debug what's going on.

For golang/go#52996.

Change-Id: Ibccbfff94f51d2c813d48b48077537090bea4612
Reviewed-on: https://go-review.googlesource.com/c/net/+/411294
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-17 18:40:16 +00:00
Damien Neil
694bf12d69 http2: add newly dialed conns to the pool before signaling completion
In dialCall.dial, close the done channel to mark dial completion after
adding the new connection to the clientConnPool.

Fixes a race condition in TestTransportBodyReadError, where the client
side of the test could observe the clientConnPool as unexpectedly
containing no conns, because the new conn had not yet been added to
the pool.

Fixes golang/go#44304.

Change-Id: I121200f9aa664fae29d0532e7fa2da47de3fe6a8
Reviewed-on: https://go-review.googlesource.com/c/net/+/410934
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-15 17:15:55 +00:00
Bryan C. Mills
c690dde000 http2: remove arbitrary timeouts in server_test.go
If the test gets completely stuck at these points, we will want a
goroutine dump in order to debug the hang, which log.Fatalf will
not produce (but a test timeout will).

If the test does not get completely stuck (as on a slow or overloaded
builder), then we should let it continue to run until the overall test
timeout, which (unlike hard-coded constants) should already take the
speed of the builder into account.

As a side-effect, this also moves some t.Fatalf calls out of
background goroutines and into the main test-function goroutines where
they belong (see golang/go#24678).

Fixes golang/go#52051.

Change-Id: I37504081e6fdf0b4c244305fc83c575e30b7b453
Reviewed-on: https://go-review.googlesource.com/c/net/+/410096
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-06-07 02:02:51 +00:00
Bryan C. Mills
c960675eff http2: eliminate arbitrary timeouts in testServerResponse
If the test deadlocks, we probably want a goroutine dump (which will
happen naturally if we allow the test to time out). Otherwise, these
arbitrary timeouts tend to only add noise on slower builders.

Fixes golang/go#53160 (maybe).

Change-Id: I2a95bf7fece27f949ab2cf9dea36fe440ac90d51
Reviewed-on: https://go-review.googlesource.com/c/net/+/409574
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-05-31 20:11:28 +00:00
Antonio Ojea
c186220193 http2: prioritize RST_STREAM frames in priority write scheduler
The http2 priority write scheduler should not queue RST_STREAM
frames with the DATA frames, and instead treat them as control frames.

There can be deadlock situations if data frames block the queue,
because if the sender wants to close the stream it sends an RST frame,
but if the client is not draining the queue, the RST frame is stuck
and the sender is not able to finish.

Fixes golang/go#49741

Signed-off-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
Change-Id: Ie4462603380039f7aba8f701fe810d1d84376efa
Reviewed-on: https://go-review.googlesource.com/c/net/+/382014
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-31 18:57:40 +00:00
Damien Neil
1d687d428a http2/h2c: support direct hand off of h2c-upgrade connections
The initial request on an h2c-upgraded connection is written as an
HTTP/1 request, with the response sent as an HTTP/2 stream.

The h2c package handled this request by constructing a sequence of
bytes representing an HTTP/2 stream containing the initial request,
prepending those bytes to the remainder of the connection, and
presenting that to the HTTP/2 server as if no upgrade had happened.
This translation did not handle request bodies. Handling request
bodies under this model would be difficult, since it would require
also translating the HTTP/2 flow control.

Rewrite the h2c upgrade to explicitly hand off the request to the
HTTP/2 server instead.

Fixes golang/go#52882.

Change-Id: I26e0f12e2b1c8b48fd36ba47baea076424983553
Reviewed-on: https://go-review.googlesource.com/c/net/+/407454
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-24 22:04:25 +00:00
renthraysk
2e3eb7b945 http2: optimization of AppendHuffmanString
This uses a uint64 bit buffer so can append 4 bytes at a time, instead
of using append every byte.

GOAMD64=v1
name                   old time/op    new time/op    delta
AppendHuffmanString-4     316ns ± 3%     169ns ± 1%  -46.60%  (p=0.000 n=10+8)

GOAMD64=v3
name                   old time/op    new time/op    delta
AppendHuffmanString-4     263ns ± 4%     114ns ± 1%  -56.68%  (p=0.000 n=10+8)

Change-Id: Ib48a0e0711589dd1b311c377f61e30d7c18c2953
GitHub-Last-Rev: 0a3eb27fee
GitHub-Pull-Request: golang/net#131
Reviewed-on: https://go-review.googlesource.com/c/net/+/403434
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-05-20 00:09:38 +00:00
Kévin Dunglas
183a9ca12b http2: exclude some header from 1xx responses
Content-Length and Transfer-Encoding must not be sent when the response
has no body.

Necessary to fix the tests of golang/go#42597.

Change-Id: Ibe90048bb122cc3ad1e04f8ebf9aa966b40489ae
GitHub-Last-Rev: 2605919859
GitHub-Pull-Request: golang/net#134
Reviewed-on: https://go-review.googlesource.com/c/net/+/406494
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-05-17 18:13:18 +00:00
Zeke Lu
45b2658723 all: fix go vet warnings
http2/h2c/h2c_test.go:27:19: golang.org/x/net/http2.Setting composite literal uses unkeyed fields
webdav/prop_test.go:152:5: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:153:5: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:191:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:202:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:217:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:227:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:241:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:251:23: encoding/xml.Name composite literal uses unkeyed fields
webdav/prop_test.go:496:23: encoding/xml.Name composite literal uses unkeyed fields
http2/transport_test.go:5310:5: call to (*T).Fatal from a non-test goroutine
http2/transport_test.go:5317:5: call to (*T).Fatal from a non-test goroutine
http2/transport_test.go:5660:3: unreachable code

Change-Id: I8dc72b976d05dc96ae18d73660c83fc9a5584ce1
GitHub-Last-Rev: a19dceaf92
GitHub-Pull-Request: golang/net#133
Reviewed-on: https://go-review.googlesource.com/c/net/+/406454
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Dan Kortschak <dan@kortschak.io>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dan Kortschak <dan@kortschak.io>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-16 13:33:12 +00:00
Kévin Dunglas
9564170430 http2: allow sending 1xx responses
Currently, it's not possible to send informational responses such as
103 Early Hints or 102 Processing.

This patch allows calling WriteHeader() multiple times in order
to send informational responses before the final one.

If the status code is in the 1xx range, the current content of the header map
is also sent. Its content is not removed after the call to WriteHeader()
because the headers must also be included in the final response.

The Chrome and Fastly teams are starting a large-scale experiment to measure
the real-life impact of the 103 status code.
Using Early Hints is proposed as a (partial) alternative to Server Push,
which are going to be removed from Chrome:
https://groups.google.com/a/chromium.org/g/blink-dev/c/K3rYLvmQUBY/m/21anpFhxAQAJ

Being able to send this status code from servers implemented using Go would
help to see if implementing it in browsers is worth it.

Fixes golang/go#26089.
Fixes golang/go#36734.
Updates golang/go#26088.

Change-Id: Iadb7be92844a3588ef4ce044f887ef5c1792f431
GitHub-Last-Rev: eee95b58b3
GitHub-Pull-Request: golang/net#96
Reviewed-on: https://go-review.googlesource.com/c/net/+/291029
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-13 22:43:57 +00:00