forked from quic-go/quic-go
use OpenStreamSync to open the data stream in the h2quic client
This commit is contained in:
@@ -168,8 +168,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
|||||||
c.cryptoChangedCond.Wait()
|
c.cryptoChangedCond.Wait()
|
||||||
}
|
}
|
||||||
hdrChan := make(chan *http.Response)
|
hdrChan := make(chan *http.Response)
|
||||||
// TODO: think about what to do with a TooManyOpenStreams error. Wait and retry?
|
dataStream, err := c.session.OpenStreamSync()
|
||||||
dataStream, err := c.session.OpenStream()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Close(err)
|
c.Close(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -181,6 +181,21 @@ var _ = Describe("Client", func() {
|
|||||||
Expect(client.session.(*mockSession).closedWithError).To(MatchError(client.headerErr))
|
Expect(client.session.(*mockSession).closedWithError).To(MatchError(client.headerErr))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("blocks if no stream is available", func() {
|
||||||
|
session.blockOpenStreamSync = true
|
||||||
|
var doReturned bool
|
||||||
|
go func() {
|
||||||
|
defer GinkgoRecover()
|
||||||
|
_, err := client.Do(request)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
doReturned = true
|
||||||
|
}()
|
||||||
|
headerStream.dataToRead.Write([]byte("invalid response"))
|
||||||
|
go client.handleHeaderStream()
|
||||||
|
|
||||||
|
Consistently(func() bool { return doReturned }).Should(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
Context("validating the address", func() {
|
Context("validating the address", func() {
|
||||||
It("refuses to do requests for the wrong host", func() {
|
It("refuses to do requests for the wrong host", func() {
|
||||||
req, err := http.NewRequest("https", "https://quic.clemente.io:1336/foobar.html", nil)
|
req, err := http.NewRequest("https", "https://quic.clemente.io:1336/foobar.html", nil)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
@@ -23,12 +24,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type mockSession struct {
|
type mockSession struct {
|
||||||
closed bool
|
closed bool
|
||||||
closedWithError error
|
closedWithError error
|
||||||
dataStream quic.Stream
|
dataStream quic.Stream
|
||||||
streamToAccept quic.Stream
|
streamToAccept quic.Stream
|
||||||
streamToOpen quic.Stream
|
streamToOpen quic.Stream
|
||||||
streamOpenErr error
|
blockOpenStreamSync bool
|
||||||
|
streamOpenErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mockSession) GetOrOpenStream(id protocol.StreamID) (quic.Stream, error) {
|
func (s *mockSession) GetOrOpenStream(id protocol.StreamID) (quic.Stream, error) {
|
||||||
@@ -44,7 +46,10 @@ func (s *mockSession) OpenStream() (quic.Stream, error) {
|
|||||||
return s.streamToOpen, nil
|
return s.streamToOpen, nil
|
||||||
}
|
}
|
||||||
func (s *mockSession) OpenStreamSync() (quic.Stream, error) {
|
func (s *mockSession) OpenStreamSync() (quic.Stream, error) {
|
||||||
panic("not implemented")
|
if s.blockOpenStreamSync {
|
||||||
|
time.Sleep(time.Hour)
|
||||||
|
}
|
||||||
|
return s.OpenStream()
|
||||||
}
|
}
|
||||||
func (s *mockSession) Close(e error) error {
|
func (s *mockSession) Close(e error) error {
|
||||||
s.closed = true
|
s.closed = true
|
||||||
|
|||||||
Reference in New Issue
Block a user