Skip to content

Commit

Permalink
unexpose unnecessary methods of Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 5, 2023
1 parent e6a9abf commit bee1599
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 45 deletions.
20 changes: 18 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,15 @@ func (c *Client) SetCommonHeadersNonCanonical(hdrs map[string]string) *Client {
// "accept-encoding",
// ).Get(url
func (c *Client) SetCommonHeaderOrder(keys ...string) *Client {
c.SetHeaderOrder(keys...)
c.Transport.WrapRoundTripFunc(func(rt http.RoundTripper) HttpRoundTripFunc {
return func(req *http.Request) (resp *http.Response, err error) {
if req.Header == nil {
req.Header = make(http.Header)
}
req.Header[HeaderOderKey] = keys
return rt.RoundTrip(req)
}
})
return c
}

Expand All @@ -897,7 +905,15 @@ func (c *Client) SetCommonHeaderOrder(keys ...string) *Client {
// ":method",
// )
func (c *Client) SetCommonPseudoHeaderOder(keys ...string) *Client {
c.SetPseudoHeaderOder(keys...)
c.Transport.WrapRoundTripFunc(func(rt http.RoundTripper) HttpRoundTripFunc {
return func(req *http.Request) (resp *http.Response, err error) {
if req.Header == nil {
req.Header = make(http.Header)
}
req.Header[PseudoHeaderOderKey] = keys
return rt.RoundTrip(req)
}
})
return c
}

Expand Down
43 changes: 0 additions & 43 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,49 +214,6 @@ func (t *Transport) WrapRoundTrip(wrappers ...HttpRoundTripWrapper) *Transport {
return t
}

// SetHeaderOrder set the order of the http header (case-insensitive).
// For example:
//
// t.SetHeaderOrder(
// "custom-header",
// "cookie",
// "user-agent",
// "accept-encoding",
// )
func (t *Transport) SetHeaderOrder(keys ...string) {
t.WrapRoundTripFunc(func(rt http.RoundTripper) HttpRoundTripFunc {
return func(req *http.Request) (resp *http.Response, err error) {
if req.Header == nil {
req.Header = make(http.Header)
}
req.Header[HeaderOderKey] = keys
return rt.RoundTrip(req)
}
})
}

// SetPseudoHeaderOder set the order of the pseudo http header (case-insensitive).
// Note this is only valid for http2 and http3.
// For example:
//
// t.SetPseudoHeaderOrder(
// ":scheme",
// ":authority",
// ":path",
// ":method",
// )
func (t *Transport) SetPseudoHeaderOder(keys ...string) {
t.WrapRoundTripFunc(func(rt http.RoundTripper) HttpRoundTripFunc {
return func(req *http.Request) (resp *http.Response, err error) {
if req.Header == nil {
req.Header = make(http.Header)
}
req.Header[PseudoHeaderOderKey] = keys
return rt.RoundTrip(req)
}
})
}

// DisableAutoDecode disable auto-detect charset and decode to utf-8
// (enabled by default).
func (t *Transport) DisableAutoDecode() *Transport {
Expand Down

0 comments on commit bee1599

Please sign in to comment.