aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/clientserver_test.go
AgeCommit message (Collapse)Author
28 hoursnet/http: temporarily disable HTTP/3 testsNicholas S. Husin
Tests for HTTP/3 are unfortunately still flaky. The flakes seem to come mostly from two sources: 1. QUIC connections are not shutdown fast enough, causing them to be detected as goroutine leaks. 2. x/net/quic has a race condition where its output buffer are written to without locks (synchronously and intentionally, for optimization), but may be asynchronously written when the QUIC stream receives a STOP_SENDING frame. Therefore, skip http3Mode for now until the above flakes are fixed. For #70914 Fixes #78701 Change-Id: If0c857c0933b977fb10a4481124680726a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/766740 Reviewed-by: Nicholas Husin <husin@google.com> Auto-Submit: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
34 hoursnet/http: fix wrong context being used when shutting down HTTP/3 serverNicholas S. Husin
t.Context was accidentally used within a t.Cleanup. This is a mistake since t.Context will always have been cancelled by the time t.Cleanup runs. This is likely the reason for flakiness in some builders: our HTTP/3 finishes before QUIC connections can finish closing asynchronously, which are then detected as goroutine leaks. To account for this, also make the shutdown context timeout more generous. For #70914 Change-Id: I0e5f06a47ef25c5df535543fc1e602f16a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/766620 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Damien Neil <dneil@google.com>
4 daysnet/http: run tests for HTTP/3 where it can already passNicholas S. Husin
By default, our test harnesses (run and runSynctest) now use http3Mode, in addition to http1Mode and http2Mode, when no []testMode were explicitly defined for a given test. Tests that cannot currently pass for HTTP/3 have been modified to use http3SkippedMode, which serves as a convenient alias for the old default of []testMode{http1Mode, http2Mode}. We changed the default mode and defined http3SkippedMode so we have a clear list of TODOs in terms of how much changes are still needed before our HTTP/3 implementation reaches basic feature parity with HTTP/1 and HTTP/2. For #70914 Change-Id: I719d5d66399a51f7c3d96180ebed9b606a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/765320 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com>
5 daysnet/http: add support for running HTTP tests against HTTP/3Nicholas S. Husin
Add support within clientserver_test.go to bring up a test HTTP/3 server and client when http3Mode testMode option is passed. To be able to reuse net/http/httptest, net/http/httptest.Server.StartTLS (and Start) have been modified so they can be called with a nil Listener. In such cases, both methods will behave identically as usual, but will not actually make its server serve or set its transport dialer, both of which requires having a listener. This should be a no-op for regular users of the package, whose entrypoint via functions such as NewServer will automatically set a local listener. Actually enabling HTTP/3 for our tests will be done in a separate CL. For #70914 Change-Id: Ibc5fc83287b6a04b46e668a54924761a92b620a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/740122 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-12net/http: use net/http/internal/http2 rather than h2_bundle.goDamien Neil
Rework net/http/internal/http2 to use internally-defined types rather than net/http types (to avoid an import cycle). Remove h2_bundle.go, and replace it with calls into net/http/internal/http2 instead. For #67810 Change-Id: I56a1b28dbd0e302ab15a30f819dd46256a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/751304 Reviewed-by: Nicholas Husin <nsh@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Nicholas Husin <husin@google.com>
2025-11-24net/http: add Transport.NewClientConnDamien Neil
For #75772 Change-Id: Iad7607b40636bab1faf8653455e92e9700309003 Reviewed-on: https://go-review.googlesource.com/c/go/+/722223 Reviewed-by: Nicholas Husin <nsh@golang.org> Reviewed-by: Nicholas Husin <husin@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-26net/http: add more tests of transport connection poolDamien Neil
Add a variety of addtional tests exercising client connection pooling, in particular HTTP/2 connection behavior. Change-Id: I7609d36db5865f1b95c903cfadb0c3233e046c09 Reviewed-on: https://go-review.googlesource.com/c/go/+/615896 Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Nicholas Husin <nsh@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-05-21net/http: use synctest.Test rather than RunDamien Neil
Use the non-experimental Test function. As a bonus, this lets us drop the hacks we were doing to support t.Cleanup inside bubbles. Change-Id: I070624e1384494e9d5fcfee594cfbb7680c1beda Reviewed-on: https://go-review.googlesource.com/c/go/+/675315 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-14net/http: use runtime.AddCleanup instead of runtime.SetFinalizerCarlos Amedee
Replace the usage of runtime.SetFinalizer with runtime.AddCleanup in tests. Updates #70907 Change-Id: Idd3f1c07f6a7709352ca09948fbcb4a0ad9418bb Reviewed-on: https://go-review.googlesource.com/c/go/+/648655 Auto-Submit: Carlos Amedee <carlos@golang.org> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-26net/http: test for racing idle conn closure and new requestsDamien Neil
TestTransportRemovesH2ConnsAfterIdle is experiencing flaky failures due to a bug in idle connection handling. Upon inspection, TestTransportRemovesH2ConnsAfterIdle is slow and (I think) not currently testing the condition that it was added to test. Using the new synctest package, this CL: - Adds a test for the failure causing flakes in this test. - Rewrites the existing test to use synctest to avoid sleeps. - Adds a new test that covers the condition the test was intended to examine. The new TestTransportIdleConnRacesRequest exercises the scenario where a never-used connection is closed by the idle-conn timer at the same time as a new request attempts to use it. In this race, the new request should either successfully use the old connection (superseding the idle timer) or should use a new connection; it should not use the closing connection and fail. TestTransportRemovesConnsAfterIdle verifies that a connection is reused before the idle timer expires, and not reused after. TestTransportRemovesConnsAfterBroken verifies that a connection is not reused after it encounters an error. This exercises the bug fixed in CL 196665, which introduced TestTransportRemovesH2ConnsAfterIdle. For #70515 Change-Id: Id23026d2903fb15ef9a831b2df71177ea177b096 Reviewed-on: https://go-review.googlesource.com/c/go/+/631795 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
2024-11-25net/http: run TestServerShutdownStateNew in a synctest bubbleDamien Neil
Took ~12s previously, ~0s now. Change-Id: I72580fbde73482a40142cf84cd3d78a50afb9f44 Reviewed-on: https://go-review.googlesource.com/c/go/+/630382 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-10-07crypto/rand: remove /dev/urandom fallback and improve getrandom batchingFilippo Valsorda
The fallback was reachable on - Linux, where starting in Go 1.24 we require a kernel with getrandom(2), see #67001. - FreeBSD, which added getrandom(2) in FreeBSD 12.0, which we require since Go 1.19. - OpenBSD, which added getentropy(2) in OpenBSD 5.6, and we only support the latest version. - DragonFly BSD, which has getrandom(2) and where we support only the latest version. - NetBSD, where we switched to kern.arandom in CL 511036, available since NetBSD 4.0. - illumos, which has getrandom(2). (Supported versions unclear.) - Solaris, which had getrandom(2) at least since Oracle Solaris 11.4. - AIX, which... ugh, fine, but that code is now in rand_aix.go. At the end of the day the platform-specific code is just a global func(b []byte) error, so simplified the package around that assumption. This also includes the following change, which used to be a separate CL. crypto/rand: improve getrandom batching and retry logic The previous logic assumed getrandom never returned short, and then applied stricter-than-necessary batch size limits, presumably to avoid short returns. This was still not sufficient because above 256 bytes getrandom(2) can be interrupted by a signal and return short *or* it can simply return EINTR if the pool is not initialized (regardless of buffer size). https://man.archlinux.org/man/getrandom.2#Interruption_by_a_signal_handler Whether this ever failed in practice is unknown: it would have been masked by the /dev/urandom fallback before. Instead, we apply buffer size limits only where necessary (really, only Solaris in practice and FreeBSD in theory) and then handle gracefully short returns and EINTR. Change-Id: I8677b457aab68a8fb6137a3b43538efc62eb7c93 It turns out that we now know that large getrandom calls *did* fail in practice, falling back on /dev/urandom, because when we removed the fallback TestBidiStreamReverseProxy with its 4KiB read started failing. https://cr-buildbucket.appspot.com/build/8740779846954406033 For #66821 Change-Id: Iaca62997604f326501a51401cdc2659c2790ff22 Reviewed-on: https://go-review.googlesource.com/c/go/+/602495 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-02all: use slices.Sorted(maps.Keys(m))Tobias Klauser
Use slices.Sorted(maps.Keys(m)) to get a sorted slices of the keys in a map. Do not change packages built during bootstrap, as the bootstrap compiler (currently 1.22.6) does not have the required maps and slices functions. Change-Id: Ie35565d241fa14aca56b730a69af010127b659ab Reviewed-on: https://go-review.googlesource.com/c/go/+/617356 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2024-07-25net: use slices and maps to clean up testsapocelipes
Replace reflect.DeepEqual with slices.Equal/maps.Equal, which is much faster. Change-Id: I54600fb63a56460c11d3d5af9072da585e31b1a2 GitHub-Last-Rev: 08c1445ad5be94d071e8ceb4b060b8f4ab0d77ba GitHub-Pull-Request: golang/go#67606 Reviewed-on: https://go-review.googlesource.com/c/go/+/587816 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-23all: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-04-08net/http: update HandlerWritesTooMuch test to allow different h1/h2 behaviorDamien Neil
Rather than requiring that HTTP/1 and HTTP/2 servers behave identically when a misbehaving handler writes too many bytes, check only that both behave reasonably. In particular, allow the handler to defer detection of a write overrun until flush time, and permit the HTTP/2 handler to reset the stream rather than requring it to return a truncated body as HTTP/1 must. For #56019 Change-Id: I0838e550c4fc202dcbb8bf39ce0fa4a367ca7e71 Reviewed-on: https://go-review.googlesource.com/c/go/+/577415 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-08-24net/http: remove arbitrary timeout from TestTransportGCRequestDamien Neil
This test expects a *Request to be garbage collected within five seconds. Some slow builders take longer. Drop the arbitrary timeout. Fixes #56809 Change-Id: I4b5bdce09002a5b52b7b5d0b33e7876d48740bc3 Reviewed-on: https://go-review.googlesource.com/c/go/+/522615 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-17net/http: eliminate more arbitrary timeouts in testsBryan C. Mills
Change-Id: I5b3158ecd0eb20dc433a53a2b03eb4551cbb3f7d Reviewed-on: https://go-review.googlesource.com/c/go/+/477196 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-01-19runtime: replace panic(nil) with panic(new(runtime.PanicNilError))Russ Cox
Long ago we decided that panic(nil) was too unlikely to bother making a special case for purposes of recover. Unfortunately, it has turned out not to be a special case. There are many examples of code in the Go ecosystem where an author has written panic(nil) because they want to panic and don't care about the panic value. Using panic(nil) in this case has the unfortunate behavior of making recover behave as though the goroutine isn't panicking. As a result, code like: func f() { defer func() { if err := recover(); err != nil { log.Fatalf("panicked! %v", err) } }() call1() call2() } looks like it guarantees that call2 has been run any time f returns, but that turns out not to be strictly true. If call1 does panic(nil), then f returns "successfully", having recovered the panic, but without calling call2. Instead you have to write something like: func f() { done := false defer func() { if err := recover(); !done { log.Fatalf("panicked! %v", err) } }() call1() call2() done = true } which defeats nearly the whole point of recover. No one does this, with the result that almost all uses of recover are subtly broken. One specific broken use along these lines is in net/http, which recovers from panics in handlers and sends back an HTTP error. Users discovered in the early days of Go that panic(nil) was a convenient way to jump out of a handler up to the serving loop without sending back an HTTP error. This was a bug, not a feature. Go 1.8 added panic(http.ErrAbortHandler) as a better way to access the feature. Any lingering code that uses panic(nil) to abort an HTTP handler without a failure message should be changed to use http.ErrAbortHandler. Programs that need the old, unintended behavior from net/http or other packages can set GODEBUG=panicnil=1 to stop the run-time error. Uses of recover that want to detect panic(nil) in new programs can check for recover returning a value of type *runtime.PanicNilError. Because the new GODEBUG is used inside the runtime, we can't import internal/godebug, so there is some new machinery to cross-connect those in this CL, to allow a mutable GODEBUG setting. That won't be necessary if we add any other mutable GODEBUG settings in the future. The CL also corrects the handling of defaulted GODEBUG values in the runtime, for #56986. Fixes #25448. Change-Id: I2b39c7e83e4f7aa308777dabf2edae54773e03f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/461956 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
2022-11-19net/http: direct server logs to test output in testsDamien Neil
Set a logger in newClientServerTest that directs the server log output to the testing.T's log, so log output gets properly associated with the test that caused it. Change-Id: I13686ca35c3e21adae16b2fc37ce36daea3df9d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/452075 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-07net/http: refactor tests to run most in HTTP/1 and HTTP/2 modesDamien Neil
Replace the ad-hoc approach to running tests in HTTP/1 and HTTP/2 modes with a 'run' function that executes a test in various modes. By default, these modes are HTTP/1 and HTTP/2, but tests can opt-in to HTTPS/1 as well. The 'run' function also takes care of post-test cleanup (running the afterTest function). The 'run' function runs tests in parallel by default. Tests which can't run in parallel (generally because they use global test hooks) pass a testNotParallel option to disable parallelism. Update clientServerTest to use t.Cleanup to clean up after itself, rather than leaving this up to tests to handle. Drop an unnecessary mutex in SetReadLoopBeforeNextReadHook. Test hooks can't be set in parallel, and we want the race detector to notify us if two simultaneous tests try to set a hook. Fixes #56032 Change-Id: I16be64913c426fc93d84abc6ad85dbd3bc191224 Reviewed-on: https://go-review.googlesource.com/c/go/+/438137 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-05-17net/http: unskip TestEarlyHintsRequest_h2Kévin Dunglas
golang/net#134 and golang/net#96 have been merged. This patch updates h2_bundle.go and enables TestEarlyHintsRequest_h2. Change-Id: Ia53fee6b3c4892a7cde10e7b62cbe7b64fa9f155 GitHub-Last-Rev: ea521b02ae1e873f9b8be6a2a3e81699d8eb5584 GitHub-Pull-Request: golang/go#52947 Reviewed-on: https://go-review.googlesource.com/c/go/+/406914 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-17net/http: allow sending 1xx responsesKévin Dunglas
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 #26089 Fixes #36734 Updates #26088 Change-Id: Ib7023c1892c35e8915d4305dd7f6373dbd00a19d GitHub-Last-Rev: 06d749d3454aa35c177a50ce4a25715df21fd742 GitHub-Pull-Request: golang/go#42597 Reviewed-on: https://go-review.googlesource.com/c/go/+/269997 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-12net/http: do not send Transfer-Encoding: identity in responsesDamien Neil
Server handlers may set a "Transfer-Encoding: identity" header on responses to disable chunking, but this header should not be sent on the wire. Fixes #49194. Change-Id: I46a9e3b8ff9d93edd7d1c34d264fc309fa322ad5 Reviewed-on: https://go-review.googlesource.com/c/go/+/359176 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>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-16net/http: try to deflake TestTransportDiscardsUnneededConnsRuss Cox
Fixes #33585. Fixes #36797. Change-Id: I9202b624642368089a9ce827e3e7a7427100bf4f Reviewed-on: https://go-review.googlesource.com/c/go/+/263144 Trust: Russ Cox <rsc@golang.org> Trust: Benny Siegert <bsiegert@gmail.com> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Benny Siegert <bsiegert@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2019-11-04net/http: support disabling built-in HTTP/2 with a new build tagBrad Fitzpatrick
Fixes #35082 Updates #6853 Change-Id: I4eeb0e15f534cff57fefb6039cd33fadf15b946e Reviewed-on: https://go-review.googlesource.com/c/go/+/205139 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: David Crawshaw <crawshaw@golang.org>
2019-10-21net/http: make TimeoutHandler log spurious WriteHeader callsEmmanuel T Odeke
Makes TimeoutHandler consistent with other handlers, by logging any spurious WriteHeader calls. Fixes #30803 Change-Id: I693fbdf8378f31bca13d579eece8e8e00eb175bf Reviewed-on: https://go-review.googlesource.com/c/go/+/200518 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-09net/http: update bundled x/net/http2Emmanuel T Odeke
Updates x/net/http2 to git rev d66e71096ffb9f08f36d9aefcae80ce319de6d68 http2: end stream eagerly after sending the request body https://golang.org/cl/181157 (fixes #32254) all: fix typos https://golang.org/cl/193799 http2: fix memory leak in random write scheduler https://golang.org/cl/198462 (fixes #33812) http2: do not sniff body if Content-Encoding is set https://golang.org/cl/199841 (updates #31753) Also unskips tests from CL 199799. Change-Id: I241c0b1cd18cad5041485be92809137a973e33bd Reviewed-on: https://go-review.googlesource.com/c/go/+/200102 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-09net/http: do not sniff response if Content-Encoding header is setEmmanuel T Odeke
Fixes #31753 Change-Id: I32ec5906ef6714e19b094f67cb0f10a211a9c500 Reviewed-on: https://go-review.googlesource.com/c/go/+/199799 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-27net/http: remove use of DeepEqual for testing errorsMarcel van Lohuizen
Comparing errors using DeepEqual breaks if frame information is added as proposed in Issue #29934. Updates #29934. Change-Id: I4ef076e262109a9d6f5b18846129df2535611d71 Reviewed-on: https://go-review.googlesource.com/c/162178 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2018-10-03net/http: log call site which causes multiple header writesDavid Url
If an illegal header write is detected, find the first caller outside of net/http using runtime.CallersFrames and include the call site in the log message. Fixes #18761 Change-Id: I92be00ac206c6ebdd60344ad7bf40a7c4c188547 Reviewed-on: https://go-review.googlesource.com/c/130997 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-02net/http: make Transport send WebSocket upgrade requests over HTTP/1Brad Fitzpatrick
WebSockets requires HTTP/1 in practice (no spec or implementations work over HTTP/2), so if we get an HTTP request that looks like it's trying to initiate WebSockets, use HTTP/1, like browsers do. This is part of a series of commits to make WebSockets work over httputil.ReverseProxy. See #26937. Updates #26937 Change-Id: I6ad3df9b0a21fddf62fa7d9cacef48e7d5d9585b Reviewed-on: https://go-review.googlesource.com/c/137437 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2018-08-21net/http: add test showing that ReverseProxy HTTP/2 bidi streaming worksBrad Fitzpatrick
Change-Id: I8361ae33c785e45e3ccc7e9bc2732c887eeb41c4 Reviewed-on: https://go-review.googlesource.com/127015 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-29net/http: update bundled http2Brad Fitzpatrick
Updates http2 to x/net/http2 git rev 97aa3a539 for: http2: dynamic table updates must occur first https://golang.org/cl/111681 http2: receiving too much data is a protocol error https://golang.org/cl/111679 http2: correct overflow protection https://golang.org/cl/111675 http2: make Server send GOAWAY if Handler sets "Connection: close" header https://golang.org/cl/121415 Fixes #20977 Change-Id: I9b8659b5191409ed007e2d911913763bcbabb7cc Reviewed-on: https://go-review.googlesource.com/121695 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-05net/http: don't validate WriteHeader code if header's already been sentBrad Fitzpatrick
Also vendors x/net/http git rev 42fe2e1c for: http2: don't check WriteHeader status if we've already sent the header https://golang.org/cl/86255 Fixes #23010 Change-Id: I4f3dd63acb52d5a34a0350aaf847a7a376d6968f Reviewed-on: https://go-review.googlesource.com/86275 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-28net/http: update bundled http2Brad Fitzpatrick
Update http2 to x/net git rev db473f6b23. (And un-skip TestWriteHeader0_h2 added in CL 80077, now fixed.) Includes: http2: remove afterReqBodyWriteError wrapper https://golang.org/cl/75252 http2: fix transport data race on reused *http.Request objects https://golang.org/cl/75530 http2: require either ECDSA or RSA ciphersuite https://golang.org/cl/30721 http2: don't log about timeouts reading client preface on new connections https://golang.org/cl/79498 http2: don't crash in Transport on server's DATA following bogus HEADERS https://golang.org/cl/80056 http2: panic on invalid WriteHeader status code https://golang.org/cl/80076 http2: fix race on ClientConn.maxFrameSize https://golang.org/cl/79238 http2: don't autodetect Content-Type when the response has an empty body https://golang.org/cl/80135 Fixes golang/go#18776 Updates golang/go#20784 Fixes golang/go#21316 Fixes golang/go#22721 Fixes golang/go#22880 Change-Id: Ie86e24e0ee2582a5a82afe5de3c7c801528be069 Reviewed-on: https://go-review.googlesource.com/80078 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tom Bergan <tombergan@google.com>
2017-11-27net/http: panic on invalid WriteHeader status codeBrad Fitzpatrick
Panic if an http Handler does: rw.WriteHeader(0) ... or other invalid values. (for a forgiving range of valid) I previously made it kinda work in https://golang.org/cl/19130 but there's no good way to fake it in HTTP/2, and we want HTTP/1 and HTTP/2 behavior to be the same, regardless of what programs do. Currently HTTP/2 omitted the :status header altogether, which was a protocol violation. In fixing that, I found CL 19130 added a test about bogus WriteHeader values with the comment: // This might change at some point, but not yet in Go 1.6. This now changes. Time to be strict. Updates golang/go#228800 Change-Id: I20eb6c0e514a31f4bba305ac4c24266f39b95fd5 Reviewed-on: https://go-review.googlesource.com/80077 Reviewed-by: Tom Bergan <tombergan@google.com>
2017-06-26net/http: fix double-close of req.BodyMatt Harden
Add a test and fix for the request body being closed twice. Fixes #19186 Change-Id: I1e35ad4aebfef68e6099c1dba7986883afdef4d7 Reviewed-on: https://go-review.googlesource.com/37298 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-17net/http: deflake TestInterruptWithPanic_nil_h2, againBrad Fitzpatrick
Updates #17243 Change-Id: Iaa737874e75fdac73452f1fc13a5749e8df78ebe Reviewed-on: https://go-review.googlesource.com/33332 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-14net/http: update bundled http2, add TestServerKeepAlivesEnabled h1/h2 testsBrad Fitzpatrick
Updates x/net/http2 to x/net git rev 6dfeb344 for: http2: make Server respect http1 Server's SetKeepAlivesEnabled https://golang.org/cl/33153 And adds a test in std. Fixes #17717 Change-Id: I3ba000abb6f3f682261e105d8a4bb93bde6609fe Reviewed-on: https://go-review.googlesource.com/33231 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tom Bergan <tombergan@google.com>
2016-11-11net/http: make Server log on bad requests from clientsKenny Grant
Fixes #12745 Change-Id: Iebb7c97cb5b68dc080644d796a6ca1c120d41b26 Reviewed-on: https://go-review.googlesource.com/27950 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-11net/http: deflake new TestInterruptWithPanic_h2Brad Fitzpatrick
TestInterruptWithPanic_h2 was added yesterday in https://golang.org/cl/33099 and https://golang.org/cl/33103 Deflake it. The http2 server sends an error before logging. Rather than reorder the http2 code to log before writing the RSTStream frame, just loop for a bit waiting for the condition we're expecting. This goes from 2 in 500 flakes for me to unreproducible. Change-Id: I062866a5977f50c820965aaf83882ddd7bf98f91 Reviewed-on: https://go-review.googlesource.com/33140 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2016-11-10net/http: update bundled http2 for ErrAbortHandler support, document it moreBrad Fitzpatrick
Updates http2 to x/net/http2 git rev 0e2717d for: http2: conditionally log stacks from panics in Server Handlers like net/http https://golang.org/cl/33102 Fixes #17790 Change-Id: Idd3f0c65540398d41b412a33f1d80de3f7f31409 Reviewed-on: https://go-review.googlesource.com/33103 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-11-10net/http: add ErrAbortHandler, make Server quiet if used as panic valueBrad Fitzpatrick
Add an explicit way for Handlers to abort their response to the client and also not spam their error log with stack traces. panic(nil) also worked in the past (for http1 at least), so continue to make that work (and test it). But ErrAbortHandler is more explicit. Updates #17790 (needs http2 updates also) Change-Id: Ib1456905b27e2ae8cf04c0983dc73e314a4a751e Reviewed-on: https://go-review.googlesource.com/33099 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-04net/http: speed up tests, use t.Parallel when it's safeBrad Fitzpatrick
Before: 8.9 seconds for go test -short After: 2.8 seconds There are still 250 tests without t.Parallel, but I got the important onces using a script: $ go test -short -v 2>&1 | go run ~/slowtests.go Where slowtests.go is https://play.golang.org/p/9mh5Wg1nLN The remaining 250 (the output lines from slowtests.go) all have a reported duration of 0ms, except one 50ms test which has to be serial. Where tests can't be parallel, I left a comment at the top saying why, so people don't add t.Parallel later and get surprised at failures. Updates #17751 Change-Id: Icbe32cbe2b996e23c89f1af6339287fa22af5115 Reviewed-on: https://go-review.googlesource.com/32684 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-11-01net/http, net/http/httptest: make http2's TrailerPrefix work for http1Brad Fitzpatrick
Go's http1 implementation originally had a mechanism to send HTTP trailers based on pre-declaring the trailer keys whose values you'd later let after the header was written. http2 copied the same mechanism, but it was found to be unsufficient for gRPC's wire protocol. A second trailer mechanism was added later (but only to http2) for handlers that want to send a trailer without knowing in advance they'd need to. Copy the same mechanism back to http1 and document it. Fixes #15754 Change-Id: I8c40d55e28b0e5b7087d3d1a904a392c56ee1f9b Reviewed-on: https://go-review.googlesource.com/32479 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-18net/http: update test to check Content-Length 0 Body more reliablyBrad Fitzpatrick
The way to send an explicitly-zero Content-Length is to set a nil Body. Fix this test to do that, rather than relying on type sniffing. Updates #17480 Updates #17071 Change-Id: I6a38e20f17013c88ec4ea69d73c507e4ed886947 Reviewed-on: https://go-review.googlesource.com/31434 TryBot-Result: Gobot Gobot <gobot@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org>
2016-10-01net/http: don't sniff Request.Body on 100-continue requests in TransportBrad Fitzpatrick
Also, update bundled http2 to x/net git rev 0d8126f to include https://golang.org/cl/30150, the HTTP/2 version of this fix. Fixes #16002 Change-Id: I8da1ca98250357aec012e3e85c8b13acfa2f3fec Reviewed-on: https://go-review.googlesource.com/30151 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>