mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
rename the EarlySession to EarlyConnection
This commit is contained in:
parent
fda9f72161
commit
6aaa9a817c
17 changed files with 232 additions and 228 deletions
|
@ -65,7 +65,7 @@ var _ = Describe("Client", func() {
|
|||
client, err := newClient("localhost:1337", nil, &roundTripperOpts{}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var dialAddrCalled bool
|
||||
dialAddr = func(_ context.Context, _ string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(_ context.Context, _ string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
|
||||
Expect(quicConf).To(Equal(defaultQuicConfig))
|
||||
Expect(tlsConf.NextProtos).To(Equal([]string{nextProtoH3}))
|
||||
Expect(quicConf.Versions).To(Equal([]protocol.VersionNumber{protocol.Version1}))
|
||||
|
@ -80,7 +80,7 @@ var _ = Describe("Client", func() {
|
|||
client, err := newClient("quic.clemente.io", nil, &roundTripperOpts{}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var dialAddrCalled bool
|
||||
dialAddr = func(_ context.Context, hostname string, _ *tls.Config, _ *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(_ context.Context, hostname string, _ *tls.Config, _ *quic.Config) (quic.EarlyConnection, error) {
|
||||
Expect(hostname).To(Equal("quic.clemente.io:443"))
|
||||
dialAddrCalled = true
|
||||
return nil, errors.New("test done")
|
||||
|
@ -100,7 +100,7 @@ var _ = Describe("Client", func() {
|
|||
client, err := newClient("localhost:1337", tlsConf, &roundTripperOpts{}, quicConf, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var dialAddrCalled bool
|
||||
dialAddr = func(_ context.Context, host string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(_ context.Context, host string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlyConnection, error) {
|
||||
Expect(host).To(Equal("localhost:1337"))
|
||||
Expect(tlsConfP.ServerName).To(Equal(tlsConf.ServerName))
|
||||
Expect(tlsConfP.NextProtos).To(Equal([]string{nextProtoH3}))
|
||||
|
@ -121,7 +121,7 @@ var _ = Describe("Client", func() {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
||||
defer cancel()
|
||||
var dialerCalled bool
|
||||
dialer := func(ctxP context.Context, network, address string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlySession, error) {
|
||||
dialer := func(ctxP context.Context, network, address string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlyConnection, error) {
|
||||
Expect(ctxP).To(Equal(ctx))
|
||||
Expect(network).To(Equal("udp"))
|
||||
Expect(address).To(Equal("localhost:1337"))
|
||||
|
@ -141,7 +141,7 @@ var _ = Describe("Client", func() {
|
|||
testErr := errors.New("handshake error")
|
||||
client, err := newClient("localhost:1337", nil, &roundTripperOpts{EnableDatagram: true}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
dialAddr = func(_ context.Context, _ string, _ *tls.Config, quicConf *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(_ context.Context, _ string, _ *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
|
||||
Expect(quicConf.EnableDatagrams).To(BeTrue())
|
||||
return nil, testErr
|
||||
}
|
||||
|
@ -153,14 +153,14 @@ var _ = Describe("Client", func() {
|
|||
testErr := errors.New("handshake error")
|
||||
client, err := newClient("localhost:1337", nil, &roundTripperOpts{}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlyConnection, error) {
|
||||
return nil, testErr
|
||||
}
|
||||
_, err = client.RoundTrip(req)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
||||
It("closes correctly if session was not created", func() {
|
||||
It("closes correctly if connection was not created", func() {
|
||||
client, err := newClient("localhost:1337", nil, &roundTripperOpts{}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(client.Close()).To(Succeed())
|
||||
|
@ -178,7 +178,7 @@ var _ = Describe("Client", func() {
|
|||
testErr := errors.New("handshake error")
|
||||
req, err := http.NewRequest("masque", "masque://quic.clemente.io:1337/foobar.html", nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlySession, error) {
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlyConnection, error) {
|
||||
return nil, testErr
|
||||
}
|
||||
_, err = client.RoundTrip(req)
|
||||
|
@ -189,7 +189,7 @@ var _ = Describe("Client", func() {
|
|||
Context("control stream handling", func() {
|
||||
var (
|
||||
request *http.Request
|
||||
sess *mockquic.MockEarlySession
|
||||
conn *mockquic.MockEarlyConnection
|
||||
settingsFrameWritten chan struct{}
|
||||
)
|
||||
testDone := make(chan struct{})
|
||||
|
@ -201,11 +201,13 @@ var _ = Describe("Client", func() {
|
|||
defer GinkgoRecover()
|
||||
close(settingsFrameWritten)
|
||||
})
|
||||
sess = mockquic.NewMockEarlySession(mockCtrl)
|
||||
sess.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
sess.EXPECT().OpenStreamSync(gomock.Any()).Return(nil, errors.New("done"))
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlySession, error) { return sess, nil }
|
||||
conn = mockquic.NewMockEarlyConnection(mockCtrl)
|
||||
conn.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
conn.EXPECT().OpenStreamSync(gomock.Any()).Return(nil, errors.New("done"))
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlyConnection, error) {
|
||||
return conn, nil
|
||||
}
|
||||
var err error
|
||||
request, err = http.NewRequest("GET", "https://quic.clemente.io:1337/file1.dat", nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -222,16 +224,16 @@ var _ = Describe("Client", func() {
|
|||
(&settingsFrame{}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
_, err := client.RoundTrip(request)
|
||||
Expect(err).To(MatchError("done"))
|
||||
time.Sleep(scaleDuration(20 * time.Millisecond)) // don't EXPECT any calls to sess.CloseWithError
|
||||
time.Sleep(scaleDuration(20 * time.Millisecond)) // don't EXPECT any calls to conn.CloseWithError
|
||||
})
|
||||
|
||||
for _, t := range []uint64{streamTypeQPACKEncoderStream, streamTypeQPACKDecoderStream} {
|
||||
|
@ -247,10 +249,10 @@ var _ = Describe("Client", func() {
|
|||
str := mockquic.NewMockStream(mockCtrl)
|
||||
str.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return str, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
|
@ -270,10 +272,10 @@ var _ = Describe("Client", func() {
|
|||
close(done)
|
||||
})
|
||||
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return str, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
|
@ -288,15 +290,15 @@ var _ = Describe("Client", func() {
|
|||
(&dataFrame{}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorMissingSettings))
|
||||
close(done)
|
||||
|
@ -314,15 +316,15 @@ var _ = Describe("Client", func() {
|
|||
buf.Write(b.Bytes()[:b.Len()-1])
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorFrameError))
|
||||
close(done)
|
||||
|
@ -337,15 +339,15 @@ var _ = Describe("Client", func() {
|
|||
quicvarint.Write(buf, streamTypePushStream)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorIDError))
|
||||
close(done)
|
||||
|
@ -362,16 +364,16 @@ var _ = Describe("Client", func() {
|
|||
(&settingsFrame{Datagram: true}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{SupportsDatagrams: false})
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{SupportsDatagrams: false})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, reason string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, reason string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorSettingsError))
|
||||
Expect(reason).To(Equal("missing QUIC Datagram support"))
|
||||
|
@ -387,7 +389,7 @@ var _ = Describe("Client", func() {
|
|||
var (
|
||||
request *http.Request
|
||||
str *mockquic.MockStream
|
||||
sess *mockquic.MockEarlySession
|
||||
conn *mockquic.MockEarlyConnection
|
||||
settingsFrameWritten chan struct{}
|
||||
)
|
||||
testDone := make(chan struct{})
|
||||
|
@ -446,13 +448,15 @@ var _ = Describe("Client", func() {
|
|||
close(settingsFrameWritten)
|
||||
}) // SETTINGS frame
|
||||
str = mockquic.NewMockStream(mockCtrl)
|
||||
sess = mockquic.NewMockEarlySession(mockCtrl)
|
||||
sess.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn = mockquic.NewMockEarlyConnection(mockCtrl)
|
||||
conn.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlySession, error) { return sess, nil }
|
||||
dialAddr = func(context.Context, string, *tls.Config, *quic.Config) (quic.EarlyConnection, error) {
|
||||
return conn, nil
|
||||
}
|
||||
var err error
|
||||
request, err = http.NewRequest("GET", "https://quic.clemente.io:1337/file1.dat", nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -465,9 +469,9 @@ var _ = Describe("Client", func() {
|
|||
|
||||
It("errors if it can't open a stream", func() {
|
||||
testErr := errors.New("stream open error")
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(nil, testErr)
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).MaxTimes(1)
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(nil, testErr)
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).MaxTimes(1)
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
_, err := client.RoundTrip(request)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
@ -476,7 +480,7 @@ var _ = Describe("Client", func() {
|
|||
testErr := errors.New("stream open error")
|
||||
request.Method = MethodGet0RTT
|
||||
// don't EXPECT any calls to HandshakeComplete()
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
buf := &bytes.Buffer{}
|
||||
str.EXPECT().Write(gomock.Any()).DoAndReturn(buf.Write).AnyTimes()
|
||||
str.EXPECT().Close()
|
||||
|
@ -492,9 +496,9 @@ var _ = Describe("Client", func() {
|
|||
It("returns a response", func() {
|
||||
rspBuf := bytes.NewBuffer(getResponse(418))
|
||||
gomock.InOrder(
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{}),
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{}),
|
||||
)
|
||||
str.EXPECT().Write(gomock.Any()).AnyTimes().DoAndReturn(func(p []byte) (int, error) { return len(p), nil })
|
||||
str.EXPECT().Close()
|
||||
|
@ -512,8 +516,8 @@ var _ = Describe("Client", func() {
|
|||
BeforeEach(func() {
|
||||
strBuf = &bytes.Buffer{}
|
||||
gomock.InOrder(
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx),
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil),
|
||||
)
|
||||
body := &mockBody{}
|
||||
body.SetData([]byte("request body"))
|
||||
|
@ -570,7 +574,7 @@ var _ = Describe("Client", func() {
|
|||
(&dataFrame{Length: 0x6}).Write(buf)
|
||||
buf.Write([]byte("foobar"))
|
||||
str.EXPECT().Close().Do(func() { close(done) })
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
str.EXPECT().CancelWrite(gomock.Any()).MaxTimes(1) // when reading the response errors
|
||||
// the response body is sent asynchronously, while already reading the response
|
||||
str.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
|
@ -583,7 +587,7 @@ var _ = Describe("Client", func() {
|
|||
It("closes the connection when the first frame is not a HEADERS frame", func() {
|
||||
buf := &bytes.Buffer{}
|
||||
(&dataFrame{Length: 0x42}).Write(buf)
|
||||
sess.EXPECT().CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), gomock.Any())
|
||||
conn.EXPECT().CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), gomock.Any())
|
||||
closed := make(chan struct{})
|
||||
str.EXPECT().Close().Do(func() { close(closed) })
|
||||
str.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
|
@ -609,7 +613,7 @@ var _ = Describe("Client", func() {
|
|||
It("cancels a request while waiting for the handshake to complete", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
req := request.WithContext(ctx)
|
||||
sess.EXPECT().HandshakeComplete().Return(context.Background())
|
||||
conn.EXPECT().HandshakeComplete().Return(context.Background())
|
||||
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
|
@ -624,8 +628,8 @@ var _ = Describe("Client", func() {
|
|||
It("cancels a request while the request is still in flight", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
req := request.WithContext(ctx)
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
sess.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
conn.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
||||
buf := &bytes.Buffer{}
|
||||
str.EXPECT().Close().MaxTimes(1)
|
||||
|
||||
|
@ -653,9 +657,9 @@ var _ = Describe("Client", func() {
|
|||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
req := request.WithContext(ctx)
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
sess.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
conn.EXPECT().OpenStreamSync(ctx).Return(str, nil)
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
buf := &bytes.Buffer{}
|
||||
str.EXPECT().Close().MaxTimes(1)
|
||||
|
||||
|
@ -673,11 +677,11 @@ var _ = Describe("Client", func() {
|
|||
|
||||
Context("gzip compression", func() {
|
||||
BeforeEach(func() {
|
||||
sess.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
conn.EXPECT().HandshakeComplete().Return(handshakeCtx)
|
||||
})
|
||||
|
||||
It("adds the gzip header to requests", func() {
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
buf := &bytes.Buffer{}
|
||||
str.EXPECT().Write(gomock.Any()).DoAndReturn(buf.Write)
|
||||
gomock.InOrder(
|
||||
|
@ -694,7 +698,7 @@ var _ = Describe("Client", func() {
|
|||
It("doesn't add gzip if the header disable it", func() {
|
||||
client, err := newClient("quic.clemente.io:1337", nil, &roundTripperOpts{DisableCompression: true}, nil, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
buf := &bytes.Buffer{}
|
||||
str.EXPECT().Write(gomock.Any()).DoAndReturn(buf.Write)
|
||||
gomock.InOrder(
|
||||
|
@ -709,8 +713,8 @@ var _ = Describe("Client", func() {
|
|||
})
|
||||
|
||||
It("decompresses the response", func() {
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
buf := &bytes.Buffer{}
|
||||
rstr := mockquic.NewMockStream(mockCtrl)
|
||||
rstr.EXPECT().Write(gomock.Any()).Do(buf.Write).AnyTimes()
|
||||
|
@ -735,8 +739,8 @@ var _ = Describe("Client", func() {
|
|||
})
|
||||
|
||||
It("only decompresses the response if the response contains the right content-encoding header", func() {
|
||||
sess.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
conn.EXPECT().OpenStreamSync(context.Background()).Return(str, nil)
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{})
|
||||
buf := &bytes.Buffer{}
|
||||
rstr := mockquic.NewMockStream(mockCtrl)
|
||||
rstr.EXPECT().Write(gomock.Any()).Do(buf.Write).AnyTimes()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue