cancel reading from the response stream when the response body is closed

This commit is contained in:
Marten Seemann
2018-12-28 20:02:51 +07:00
parent d6521fa3cc
commit 05be874b11
8 changed files with 106 additions and 26 deletions

View File

@@ -19,7 +19,7 @@ import (
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Client tests", func() {
var _ = Describe("HTTP tests", func() {
var client *http.Client
versions := protocol.SupportedVersions
@@ -43,7 +43,8 @@ var _ = Describe("Client tests", func() {
RootCAs: testdata.GetRootCA(),
},
QuicConfig: &quic.Config{
Versions: []protocol.VersionNumber{version},
Versions: []protocol.VersionNumber{version},
IdleTimeout: 10 * time.Second,
},
},
}
@@ -76,6 +77,17 @@ var _ = Describe("Client tests", func() {
Expect(body).To(Equal(testserver.PRDataLong))
})
It("downloads many files, if the response is not read", func() {
const num = 150
for i := 0; i < num; i++ {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/prdata")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
Expect(resp.Body.Close()).To(Succeed())
}
})
It("uploads a file", func() {
resp, err := client.Post(
"https://localhost:"+testserver.Port()+"/echo",

View File

@@ -40,32 +40,27 @@ func init() {
var err error
l, err := strconv.Atoi(sl)
Expect(err).NotTo(HaveOccurred())
_, err = w.Write(GeneratePRData(l))
Expect(err).NotTo(HaveOccurred())
w.Write(GeneratePRData(l)) // don't check the error here. Stream may be reset.
} else {
_, err := w.Write(PRData)
Expect(err).NotTo(HaveOccurred())
w.Write(PRData) // don't check the error here. Stream may be reset.
}
})
http.HandleFunc("/prdatalong", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
_, err := w.Write(PRDataLong)
Expect(err).NotTo(HaveOccurred())
w.Write(PRDataLong) // don't check the error here. Stream may be reset.
})
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
_, err := io.WriteString(w, "Hello, World!\n")
Expect(err).NotTo(HaveOccurred())
io.WriteString(w, "Hello, World!\n") // don't check the error here. Stream may be reset.
})
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
body, err := ioutil.ReadAll(r.Body)
Expect(err).NotTo(HaveOccurred())
_, err = w.Write(body)
Expect(err).NotTo(HaveOccurred())
w.Write(body) // don't check the error here. Stream may be reset.
})
}