diff options
| author | Emmanuel T Odeke <emmanuel@orijtech.com> | 2019-10-16 16:05:24 -0700 |
|---|---|---|
| committer | Emmanuel Odeke <emm.odeke@gmail.com> | 2019-10-18 19:29:10 +0000 |
| commit | 5375c71289917ac7b25c6fa4bb0f4fa17be19a07 (patch) | |
| tree | ec0d6410663c76ab891ed6630c6b9876da135186 /src/net/http/httptest/example_test.go | |
| parent | dc3b7883b5f11812785a8561afb5ee33e9f15f69 (diff) | |
| download | go-5375c71289917ac7b25c6fa4bb0f4fa17be19a07.tar.xz | |
net/http/httptest: add EnableHTTP2 to Server
Adds a knob EnableHTTP2, that enables an unstarted
Server and its respective client to speak HTTP/2,
but only after StartTLS has been invoked.
Fixes #34939
Change-Id: I287c568b8708a4d3c03e7d9eca7c323b8f4c65b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/201557
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/httptest/example_test.go')
| -rw-r--r-- | src/net/http/httptest/example_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/net/http/httptest/example_test.go b/src/net/http/httptest/example_test.go index e3d392130e..54e77dbb84 100644 --- a/src/net/http/httptest/example_test.go +++ b/src/net/http/httptest/example_test.go @@ -55,6 +55,28 @@ func ExampleServer() { // Output: Hello, client } +func ExampleServer_hTTP2() { + ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %s", r.Proto) + })) + ts.EnableHTTP2 = true + ts.StartTLS() + defer ts.Close() + + res, err := ts.Client().Get(ts.URL) + if err != nil { + log.Fatal(err) + } + greeting, err := ioutil.ReadAll(res.Body) + res.Body.Close() + if err != nil { + log.Fatal(err) + } + fmt.Printf("%s", greeting) + + // Output: Hello, HTTP/2.0 +} + func ExampleNewTLSServer() { ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello, client") |
