Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client provides the basic API for sending HTTP requests
Example ¶
cl := &Client{} resp, err := cl.CtxDo(context.Background(), &Request{ Method: "GET", URL: "http://www.google.com/?a=b", Header: http.Header{ // "Connection": {"close"}, }, }) if err != nil { fmt.Println(err) return } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) fmt.Println(err) fmt.Println(string(b))
Output:
type CoreDialer ¶
type CoreDialer = dialer.CoreDialer
CoreDialer is the default implementation of the Dialer interface. It would be used by a zero value Client.
type Dialer ¶
Dialers are responsible for creating underlying streams that http requests could be written to and responses could be read from. for example, opening a raw TCP connection for HTTP/1.1 requests.
Unlike net/http.Transport, A Dialer MUST NOT hold active connection states, which means a Dialer must be able to be swapped out from a Client without pain. Like net/http.Transport, it SHOULD hold the connection related configs like [ProxyConfiguration] or *net/tls.Config.
type ProxyConfig ¶
type ProxyConfig = dialer.ProxyConfig
type Request ¶
Requests are re-usable objects that are high-level representations of a HTTP request. A request would be "prepared" into *[PreparedRequest]s to be actually written into an underlying connection (i.e. a TCP stream)
type ResolveConfig ¶
type ResolveConfig = dialer.ResolveConfig
we need a dedicated resolver for two scenarios:
- Resolve remote address locally in proxied requests
- to customize the DNS server used for resolving hostname
the standard library didn't provide a intuitive way of setting DNS server addresses since it only follows the system configuration (e.g. /etc/resolv.conf), leaving us only one option of using net.Resolver.Dial hook with a Go Resolver.
this part of code tries to take advantage of that only option as far as possible to provide a relativly intuitive configuration API.