diff --git a/http/client.go b/http/client.go index b854f6b..ff84425 100644 --- a/http/client.go +++ b/http/client.go @@ -27,6 +27,11 @@ import ( "golang.org/x/net/http/httpguts" ) +// ErrUseLastResponse can be returned by Client.CheckRedirect to control how +// redirects are processed: the most recent response is returned with its body +// unclosed, and the error is nil. TINYGO: provided for API compatibility. +var ErrUseLastResponse = errors.New("net/http: use last response") + // A Client is an HTTP client. Its zero value ([DefaultClient]) is a // usable client that uses [DefaultTransport]. // @@ -585,3 +590,13 @@ func (c *Client) Head(url string) (resp *Response, err error) { } return c.Do(req) } + +// CloseIdleConnections closes any connections on its Transport which were +// previously connected from previous requests but are now idle. It delegates to +// the Transport's CloseIdleConnections if it has one. +func (c *Client) CloseIdleConnections() { + type closeIdler interface{ CloseIdleConnections() } + if tr, ok := c.Transport.(closeIdler); ok { + tr.CloseIdleConnections() + } +} diff --git a/http/transport.go b/http/transport.go index 1f7ac3c..970f7fa 100644 --- a/http/transport.go +++ b/http/transport.go @@ -34,6 +34,12 @@ type readTrackingBody struct { // golang.org/x/net/http2 and google.golang.org/grpc. They are stored but, aside // from fetch, have no effect at runtime. type Transport struct { + // Proxy specifies a function to return a proxy for a given Request. + // + // TINYGO: present for API compatibility; the netdev-backed transport dials + // directly and does not consult it. + Proxy func(*Request) (*url.URL, error) + // TLSClientConfig specifies the TLS configuration to use with tls.Client. TLSClientConfig *tls.Config @@ -130,6 +136,14 @@ func ProxyFromEnvironment(req *Request) (*url.URL, error) { return nil, nil } +// ProxyURL returns a proxy function (for use in a Transport) that always returns +// the same URL. +func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error) { + return func(*Request) (*url.URL, error) { + return fixedURL, nil + } +} + // ErrSkipAltProtocol is a sentinel error value defined by Transport.RegisterProtocol. var ErrSkipAltProtocol = errors.New("net/http: skip alternate protocol")