forked from quic-go/quic-go
fix mutexes for writing requests in h2quic client
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user