gospdy
gospdy copied to clipboard
client: Awkward to use different priorities with the same Transport
Given that the connection pool is inside Transport, to have multiple streams on the same connection one must use the same Transport.
However, to make requests with different priorities, the API is to set fields in RequestExtra, and then e.g. http.Client.Get. So, in practice, that would mean one needs to have a mutex protecting RequestExtra, and do something like Lock; RequestExtra.Priority = ...; Get; Unlock.
I understand that there is no good place for a priority in the net/http APIs. Maybe there could be per-priority RoundTrippers? In fact, all of RequestExtra could be done like that. Something like:
type customTransport struct {
RequestExtra
*Transport
}
func (t *customTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
return t.Transport.roundTrip(req, &t.RequestExtra)
}
func (t *Transport) Custom(extra RequestExtra) http.RoundTripper {
return &customTransport{RequestExtra: extra, Transport: t}
}
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
return t.roundTrip(req, &RequestExtra{})
}
func (t *Transport) roundTrip(req *http.Request, extra *RequestExtra) (resp *http.Response, err error) {
...
}