]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: test max request body size against both HTTP/1 and HTTP/2
authorBurcu Dogan <jbd@google.com>
Fri, 4 Dec 2015 19:12:39 +0000 (11:12 -0800)
committerBurcu Dogan <jbd@google.com>
Fri, 4 Dec 2015 19:54:05 +0000 (19:54 +0000)
Change-Id: I009eaa52d03f1c3af33a6e884332f41c7cf48edd
Reviewed-on: https://go-review.googlesource.com/17427
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/serve_test.go

index 15e26a59df1835582108662f894d44204278305d..91eab137b75041c41abecccf651b316dc8921087 100644 (file)
@@ -2027,10 +2027,13 @@ func (cr countReader) Read(p []byte) (n int, err error) {
        return
 }
 
-func TestRequestBodyLimit(t *testing.T) {
+func TestRequestBodyLimit_h1(t *testing.T) { testRequestBodyLimit(t, false) }
+func TestRequestBodyLimit_h2(t *testing.T) { testRequestBodyLimit(t, true) }
+
+func testRequestBodyLimit(t *testing.T, h2 bool) {
        defer afterTest(t)
        const limit = 1 << 20
-       ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
+       cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
                r.Body = MaxBytesReader(w, r.Body, limit)
                n, err := io.Copy(ioutil.Discard, r.Body)
                if err == nil {
@@ -2040,10 +2043,10 @@ func TestRequestBodyLimit(t *testing.T) {
                        t.Errorf("io.Copy = %d, want %d", n, limit)
                }
        }))
-       defer ts.Close()
+       defer cst.close()
 
        nWritten := new(int64)
-       req, _ := NewRequest("POST", ts.URL, io.LimitReader(countReader{neverEnding('a'), nWritten}, limit*200))
+       req, _ := NewRequest("POST", cst.ts.URL, io.LimitReader(countReader{neverEnding('a'), nWritten}, limit*200))
 
        // Send the POST, but don't care it succeeds or not.  The
        // remote side is going to reply and then close the TCP
@@ -2054,7 +2057,7 @@ func TestRequestBodyLimit(t *testing.T) {
        //
        // But that's okay, since what we're really testing is that
        // the remote side hung up on us before we wrote too much.
-       _, _ = DefaultClient.Do(req)
+       _, _ = cst.c.Do(req)
 
        if atomic.LoadInt64(nWritten) > limit*100 {
                t.Errorf("handler restricted the request body to %d bytes, but client managed to write %d",