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 {
|
for c.encryptionLevel != protocol.EncryptionForwardSecure {
|
||||||
c.cryptoChangedCond.Wait()
|
c.cryptoChangedCond.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
hdrChan := make(chan *http.Response)
|
hdrChan := make(chan *http.Response)
|
||||||
c.responses[dataStreamID] = hdrChan
|
c.responses[dataStreamID] = hdrChan
|
||||||
|
c.mutex.Unlock()
|
||||||
|
|
||||||
dataStream, err := c.client.OpenStream(dataStreamID)
|
dataStream, err := c.client.OpenStream(dataStreamID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -169,7 +170,6 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c.mutex.Unlock()
|
|
||||||
|
|
||||||
var res *http.Response
|
var res *http.Response
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
@@ -16,6 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type requestWriter struct {
|
type requestWriter struct {
|
||||||
|
mutex sync.Mutex
|
||||||
headerStream utils.Stream
|
headerStream utils.Stream
|
||||||
|
|
||||||
henc *hpack.Encoder
|
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 trailers
|
||||||
// TODO: add support for gzip compression
|
// TODO: add support for gzip compression
|
||||||
// TODO: write continuation frames, if the header frame is too long
|
// TODO: write continuation frames, if the header frame is too long
|
||||||
|
|
||||||
|
w.mutex.Lock()
|
||||||
|
defer w.mutex.Unlock()
|
||||||
|
|
||||||
w.encodeHeaders(req, false, "", actualContentLength(req))
|
w.encodeHeaders(req, false, "", actualContentLength(req))
|
||||||
h2framer := http2.NewFramer(w.headerStream, nil)
|
h2framer := http2.NewFramer(w.headerStream, nil)
|
||||||
return h2framer.WriteHeaders(http2.HeadersFrameParam{
|
return h2framer.WriteHeaders(http2.HeadersFrameParam{
|
||||||
|
|||||||
Reference in New Issue
Block a user