Skip to content

Commit

Permalink
Add SetHTTP2PriorityFrames support to Client and Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 4, 2023
1 parent 6c5a082 commit fec12cb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,12 @@ func (c *Client) SetHTTP2HeaderPriority(priority http2.PriorityParam) *Client {
return c
}

// SetHTTP2PriorityFrames set the ordered http2 priority frames.
func (c *Client) SetHTTP2PriorityFrames(frames ...http2.PriorityFrame) *Client {
c.Transport.SetHTTP2PriorityFrames(frames...)
return c
}

// SetCommonContentType set the `Content-Type` header for requests fired
// from the client.
func (c *Client) SetCommonContentType(ct string) *Client {
Expand Down
12 changes: 12 additions & 0 deletions client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,18 @@ func SetHTTP2ConnectionFlow(flow uint32) *Client {
return defaultClient.SetHTTP2ConnectionFlow(flow)
}

// SetHTTP2HeaderPriority is a global wrapper methods which delegated
// to the default client's Client.SetHTTP2HeaderPriority.
func SetHTTP2HeaderPriority(priority http2.PriorityParam) *Client {
return defaultClient.SetHTTP2HeaderPriority(priority)
}

// SetHTTP2PriorityFrames is a global wrapper methods which delegated
// to the default client's Client.SetHTTP2PriorityFrames.
func SetHTTP2PriorityFrames(frames ...http2.PriorityFrame) *Client {
return defaultClient.SetHTTP2PriorityFrames(frames...)
}

// SetHTTP2MaxHeaderListSize is a global wrapper methods which delegated
// to the default client's Client.SetHTTP2MaxHeaderListSize.
func SetHTTP2MaxHeaderListSize(max uint32) *Client {
Expand Down
6 changes: 6 additions & 0 deletions http2/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ type PriorityParam struct {
func (p PriorityParam) IsZero() bool {
return p == PriorityParam{}
}

// PriorityFrame represents a http priority frame.
type PriorityFrame struct {
StreamID uint32
PriorityParam PriorityParam
}
7 changes: 7 additions & 0 deletions internal/http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type Transport struct {

ConnectionFlow uint32
HeaderPriority http2.PriorityParam
PriorityFrames []http2.PriorityFrame

connPoolOnce sync.Once
connPoolOrDef ClientConnPool // non-nil version of ConnPool
Expand Down Expand Up @@ -703,6 +704,12 @@ func (t *Transport) newClientConn(c net.Conn, singleUse bool) (*ClientConn, erro
connFlow = transportDefaultConnFlow
}
cc.fr.WriteWindowUpdate(0, connFlow)

for _, p := range t.PriorityFrames {
cc.fr.WritePriority(p.StreamID, p.PriorityParam)
cc.nextStreamID = p.StreamID + 2
}

cc.inflow.init(int32(connFlow) + initialWindowSize)
cc.bw.Flush()
if cc.werr != nil {
Expand Down
6 changes: 6 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ func (t *Transport) SetHTTP2HeaderPriority(priority http2.PriorityParam) *Transp
return t
}

// SetHTTP2PriorityFrames set the ordered http2 priority frames.
func (t *Transport) SetHTTP2PriorityFrames(frames ...http2.PriorityFrame) *Transport {
t.t2.PriorityFrames = frames
return t
}

// SetTLSClientConfig set the custom TLSClientConfig, which specifies the TLS configuration to
// use with tls.Client.
// If nil, the default configuration is used.
Expand Down

0 comments on commit fec12cb

Please sign in to comment.