implement HTTP/3

This commit is contained in:
Marten Seemann
2019-03-11 15:06:23 +09:00
parent 1325909ab7
commit 4f6d0e651a
43 changed files with 2511 additions and 2540 deletions

View File

@@ -9,7 +9,7 @@ import (
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/h2quic"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
@@ -38,7 +38,7 @@ var _ = Describe("HTTP tests", func() {
Context(fmt.Sprintf("with QUIC version %s", version), func() {
BeforeEach(func() {
client = &http.Client{
Transport: &h2quic.RoundTripper{
Transport: &http3.RoundTripper{
TLSClientConfig: &tls.Config{
RootCAs: testdata.GetRootCA(),
},
@@ -77,8 +77,20 @@ var _ = Describe("HTTP tests", func() {
Expect(body).To(Equal(testserver.PRDataLong))
})
// TODO(#1756): this test times out
PIt("downloads many files, if the response is not read", func() {
It("downloads many hellos", func() {
const num = 150
for i := 0; i < num; i++ {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/hello")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 3*time.Second))
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Hello, World!\n"))
}
})
It("downloads many files, if the response is not read", func() {
const num = 150
for i := 0; i < num; i++ {
@@ -89,6 +101,19 @@ var _ = Describe("HTTP tests", func() {
}
})
It("posts a small message", func() {
resp, err := client.Post(
"https://localhost:"+testserver.Port()+"/echo",
"text/plain",
bytes.NewReader([]byte("Hello, world!")),
)
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
Expect(err).ToNot(HaveOccurred())
Expect(body).To(Equal([]byte("Hello, world!")))
})
It("uploads a file", func() {
resp, err := client.Post(
"https://localhost:"+testserver.Port()+"/echo",
@@ -99,7 +124,7 @@ var _ = Describe("HTTP tests", func() {
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
Expect(err).ToNot(HaveOccurred())
Expect(bytes.Equal(body, testserver.PRData)).To(BeTrue())
Expect(body).To(Equal(testserver.PRData))
})
})
}

View File

@@ -8,7 +8,7 @@ import (
"strconv"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/h2quic"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
@@ -27,7 +27,7 @@ var (
// PRDataLong contains dataLenLong bytes of pseudo-random data.
PRDataLong = GeneratePRData(dataLenLong)
server *h2quic.Server
server *http3.Server
stoppedServing chan struct{}
port string
)
@@ -75,10 +75,10 @@ func GeneratePRData(l int) []byte {
return res
}
// StartQuicServer starts a h2quic.Server.
// StartQuicServer starts a http3.Server.
// versions is a slice of supported QUIC versions. It may be nil, then all supported versions are used.
func StartQuicServer(versions []protocol.VersionNumber) {
server = &h2quic.Server{
server = &http3.Server{
Server: &http.Server{
TLSConfig: testdata.GetTLSConfig(),
},
@@ -102,7 +102,7 @@ func StartQuicServer(versions []protocol.VersionNumber) {
}()
}
// StopQuicServer stops the h2quic.Server.
// StopQuicServer stops the http3.Server.
func StopQuicServer() {
Expect(server.Close()).NotTo(HaveOccurred())
Eventually(stoppedServing).Should(BeClosed())