forked from quic-go/quic-go
return handshake errors in h2quic Client.Do
This commit is contained in:
@@ -31,6 +31,7 @@ type Client struct {
|
|||||||
|
|
||||||
hostname string
|
hostname string
|
||||||
encryptionLevel protocol.EncryptionLevel
|
encryptionLevel protocol.EncryptionLevel
|
||||||
|
handshakeErr error
|
||||||
dialChan chan struct{} // will be closed once the handshake is complete and the header stream has been opened
|
dialChan chan struct{} // will be closed once the handshake is complete and the header stream has been opened
|
||||||
|
|
||||||
session quic.Session
|
session quic.Session
|
||||||
@@ -60,8 +61,12 @@ func NewClient(t *QuicRoundTripper, tlsConfig *tls.Config, hostname string) *Cli
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dial dials the connection
|
// Dial dials the connection
|
||||||
func (c *Client) Dial() error {
|
func (c *Client) Dial() (err error) {
|
||||||
var err error
|
defer func() {
|
||||||
|
c.handshakeErr = err
|
||||||
|
close(c.dialChan)
|
||||||
|
}()
|
||||||
|
|
||||||
c.session, err = c.dialAddr(c.hostname, c.config)
|
c.session, err = c.dialAddr(c.hostname, c.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -77,8 +82,7 @@ func (c *Client) Dial() error {
|
|||||||
}
|
}
|
||||||
c.requestWriter = newRequestWriter(c.headerStream)
|
c.requestWriter = newRequestWriter(c.headerStream)
|
||||||
go c.handleHeaderStream()
|
go c.handleHeaderStream()
|
||||||
close(c.dialChan)
|
return
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) handleHeaderStream() {
|
func (c *Client) handleHeaderStream() {
|
||||||
@@ -143,7 +147,12 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
|||||||
|
|
||||||
hasBody := (req.Body != nil)
|
hasBody := (req.Body != nil)
|
||||||
|
|
||||||
<-c.dialChan // wait until the handshake has completed
|
// wait until the handshake is complete
|
||||||
|
<-c.dialChan
|
||||||
|
if c.handshakeErr != nil {
|
||||||
|
return nil, c.handshakeErr
|
||||||
|
}
|
||||||
|
|
||||||
responseChan := make(chan *http.Response)
|
responseChan := make(chan *http.Response)
|
||||||
dataStream, err := c.session.OpenStreamSync()
|
dataStream, err := c.session.OpenStreamSync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -92,6 +92,23 @@ var _ = Describe("Client", func() {
|
|||||||
Expect(err).To(MatchError(testErr))
|
Expect(err).To(MatchError(testErr))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("returns a request when dial fails", func() {
|
||||||
|
testErr := errors.New("dial error")
|
||||||
|
client.dialAddr = func(hostname string, conf *quic.Config) (quic.Session, error) {
|
||||||
|
return nil, testErr
|
||||||
|
}
|
||||||
|
request, err := http.NewRequest("https", "https://quic.clemente.io:1337/file1.dat", nil)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
var doErr error
|
||||||
|
go func() {
|
||||||
|
_, doErr = client.Do(request)
|
||||||
|
}()
|
||||||
|
err = client.Dial()
|
||||||
|
Expect(err).To(MatchError(testErr))
|
||||||
|
Eventually(func() error { return doErr }).Should(MatchError(testErr))
|
||||||
|
})
|
||||||
|
|
||||||
Context("Doing requests", func() {
|
Context("Doing requests", func() {
|
||||||
var request *http.Request
|
var request *http.Request
|
||||||
var dataStream *mockStream
|
var dataStream *mockStream
|
||||||
|
|||||||
Reference in New Issue
Block a user