Skip to content

Commit

Permalink
wrap more methods for client
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Jul 6, 2022
1 parent 7eb9617 commit bf37526
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 7 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (c *Client) SetCommonDumpOptions(opt *DumpOptions) *Client {

// SetProxy set the proxy function.
func (c *Client) SetProxy(proxy func(*http.Request) (*urlpkg.URL, error)) *Client {
c.t.Proxy = proxy
c.t.SetProxy(proxy)
return c
}

Expand All @@ -681,7 +681,8 @@ func (c *Client) SetProxyURL(proxyUrl string) *Client {
c.log.Errorf("failed to parse proxy url %s: %v", proxyUrl, err)
return c
}
c.t.Proxy = http.ProxyURL(u)
proxy := http.ProxyURL(u)
c.t.SetProxy(proxy)
return c
}

Expand Down Expand Up @@ -732,22 +733,22 @@ func (c *Client) SetXmlUnmarshal(fn func(data []byte, v interface{}) error) *Cli
}

// SetDialTLS set the customized `DialTLSContext` function to Transport.
// Make sure the returned `conn` implements TLSConn if you want your
// Make sure the returned `conn` implements pkg/tls.Conn if you want your
// customized `conn` supports HTTP2.
func (c *Client) SetDialTLS(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client {
c.t.DialTLSContext = fn
c.t.SetDialTLS(fn)
return c
}

// SetDial set the customized `DialContext` function to Transport.
func (c *Client) SetDial(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client {
c.t.DialContext = fn
c.t.SetDial(fn)
return c
}

// SetTLSHandshakeTimeout set the TLS handshake timeout.
func (c *Client) SetTLSHandshakeTimeout(timeout time.Duration) *Client {
c.t.TLSHandshakeTimeout = timeout
c.t.SetTLSHandshakeTimeout(timeout)
return c
}

Expand Down
12 changes: 12 additions & 0 deletions client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ func EnableForceHTTP2() *Client {
return defaultClient.EnableForceHTTP2()
}

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

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

// DisableForceHttpVersion is a global wrapper methods which delegated
// to the default client's DisableForceHttpVersion.
func DisableForceHttpVersion() *Client {
Expand Down
2 changes: 2 additions & 0 deletions client_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func TestGlobalWrapper(t *testing.T) {
SetRedirectPolicy(NoRedirectPolicy()),
EnableForceHTTP1(),
EnableForceHTTP2(),
EnableForceHTTP3(),
EnableHTTP3(),
DisableForceHttpVersion(),
SetAutoDecodeContentType("json"),
SetAutoDecodeContentTypeFunc(func(contentType string) bool { return true }),
Expand Down

0 comments on commit bf37526

Please sign in to comment.