From bee1599f0f3ee1a3901d175a1cf40e98444784f2 Mon Sep 17 00:00:00 2001 From: roc Date: Sat, 5 Aug 2023 11:43:27 +0800 Subject: [PATCH] unexpose unnecessary methods of Transport --- client.go | 20 ++++++++++++++++++-- transport.go | 43 ------------------------------------------- 2 files changed, 18 insertions(+), 45 deletions(-) diff --git a/client.go b/client.go index 6a36e44a..4bf54009 100644 --- a/client.go +++ b/client.go @@ -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 } @@ -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 } diff --git a/transport.go b/transport.go index 2511b056..80106d8e 100644 --- a/transport.go +++ b/transport.go @@ -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 {