aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/example_test.go
AgeCommit message (Collapse)Author
2025-08-11net/http: add example for CrossOriginProtectionBracken Dawson
It's not immediately appaerent that a method must be used to wrap the handler, so add a basic example to guide users to the right API. Fixes #74121 Change-Id: I23fc3dff6fff9bf4eb29c099bc77da8c99620671 Reviewed-on: https://go-review.googlesource.com/c/go/+/681256 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-11-05net/http: add Protocols field to Server and TransportDamien Neil
Support configuring which HTTP version(s) a server or client use via an explicit set of protocols. The Protocols field takes precedence over TLSNextProto and ForceAttemptHTTP2. Fixes #67814 Change-Id: I09ece88f78ad4d98ca1f213157b5f62ae11e063f Reviewed-on: https://go-review.googlesource.com/c/go/+/607496 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-19net/http: make ExampleGet show StatusCode checks for non-1XX,2XX responsesEmmanuel T Odeke
Updates ExampleGet to show how to handle bad responses with non-1XX,2XX status codes. Given that the canonical examples are copied, we need to have them properly check against failures. This is a bug I've seen often in the wild, that's exacerbated when for example unmarshalling JSON or even protobufs, and no errors are returned by the decoders, so code fails silently after making a request for example to a gateway that they were unauthorized to access. Fixes #39778 Change-Id: I1cd688f2fab47581c8cf228235d3662b4c8e4315 Reviewed-on: https://go-review.googlesource.com/c/go/+/299609 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
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>
2019-07-05net/http: stop ExampleServer_Shutdown from hanging on errorPatrik Lundin
Running the example code when not having permissions to bind to port 80 will cause the program to hang after printing the error message. Change-Id: I2433ba2629b362fc8f1731e40cab5eea72ec354f GitHub-Last-Rev: 0bb3dc08b6f646470fc6ff208ea12bca901a2299 GitHub-Pull-Request: golang/go#32947 Reviewed-on: https://go-review.googlesource.com/c/go/+/185157 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-27net/http: add http.NotFoundHandler exampleesell
Change-Id: I6a69c7a5b829a967d75e1c79210a4906c0d8f505 Reviewed-on: https://go-review.googlesource.com/132276 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-30net/http: add example for http.HandleFuncDavid Timm
Change-Id: Id0e2fb2abad5b776ac0ed76e55e36c6b774b5b7a Reviewed-on: https://go-review.googlesource.com/132278 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-24net/http: fix and normalize the [Server.][ListenAnd]Serve[TLS] docsFilippo Valsorda
The only inaccurate part was the HTTP/2 caveat in Server.ServeTLS, which only applies to the plain Serve variant. The restriction implemented in shouldConfigureHTTP2ForServe is not on the setupHTTP2_ServeTLS codepath because ServeTLS owns the tls.Listener, so we fix it for the user instead of disabling HTTP/2. Fixes #24607 Change-Id: Ie5f207d0201f09db27bf81b75535e5f6fdaf91e2 Reviewed-on: https://go-review.googlesource.com/103815 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-14net/http: add example to Server.ShutdownStephen McQuay (smcquay)
Fixes #19579 Change-Id: Id99ca6de94d8d895dfaed1ed507e9d36c7f60670 Reviewed-on: https://go-review.googlesource.com/48869 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-20net/http: add example for setting trailers in an HandlerBrad Fitzpatrick
Change-Id: I6a8bb853a538c80d95589321d3226784bc017eef Reviewed-on: https://go-review.googlesource.com/12327 Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.