diff --git a/h2quic/client.go b/h2quic/client.go index d34863eb..58534711 100644 --- a/h2quic/client.go +++ b/h2quic/client.go @@ -158,9 +158,10 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { for c.encryptionLevel != protocol.EncryptionForwardSecure { c.cryptoChangedCond.Wait() } - hdrChan := make(chan *http.Response) c.responses[dataStreamID] = hdrChan + c.mutex.Unlock() + dataStream, err := c.client.OpenStream(dataStreamID) if err != nil { return nil, err @@ -169,7 +170,6 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { if err != nil { return nil, err } - c.mutex.Unlock() var res *http.Response select { diff --git a/h2quic/request_writer.go b/h2quic/request_writer.go index c77fcbd6..7f421adc 100644 --- a/h2quic/request_writer.go +++ b/h2quic/request_writer.go @@ -6,6 +6,7 @@ import ( "net/http" "strconv" "strings" + "sync" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" @@ -16,6 +17,7 @@ import ( ) type requestWriter struct { + mutex sync.Mutex headerStream utils.Stream henc *hpack.Encoder @@ -36,6 +38,10 @@ func (w *requestWriter) WriteRequest(req *http.Request, dataStreamID protocol.St // TODO: add support for trailers // TODO: add support for gzip compression // TODO: write continuation frames, if the header frame is too long + + w.mutex.Lock() + defer w.mutex.Unlock() + w.encodeHeaders(req, false, "", actualContentLength(req)) h2framer := http2.NewFramer(w.headerStream, nil) return h2framer.WriteHeaders(http2.HeadersFrameParam{