Documentation
¶
Overview ¶
Package http2 is the same as the standard http lib with HTTP2 client support
Index ¶
- Variables
- func Get(url string) (resp *http.Response, err error)
- func Head(url string) (resp *http.Response, err error)
- func Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
- func PostForm(url string, data url.Values) (resp *http.Response, err error)
- func SetDefaultClientTimeout(t time.Duration)
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = http.Client{ Transport: &http2.Transport{ DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { host, port, err := net.SplitHostPort(addr) if err != nil { return nil, err } addrs, err := dns.LookupHost(ctx, host) if err != nil { return nil, err } if len(addrs) == 0 { return nil, ErrEmptyHostAddress } var conn net.Conn var tlsConn *tls.Conn for _, a := range addrs { if defaultDialer.Timeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(context.Background(), defaultDialer.Timeout) defer cancel() } else if !defaultDialer.Deadline.IsZero() { var cancel context.CancelFunc ctx, cancel = context.WithDeadline(context.Background(), defaultDialer.Deadline) defer cancel() } conn, err = defaultDialer.DialContext(ctx, network, net.JoinHostPort(a, port)) if err != nil { continue } tlsConn = tls.Client(terasu.NewConn(conn), cfg) if defaultDialer.Timeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(context.Background(), defaultDialer.Timeout) defer cancel() } else if !defaultDialer.Deadline.IsZero() { var cancel context.CancelFunc ctx, cancel = context.WithDeadline(context.Background(), defaultDialer.Deadline) defer cancel() } err = tlsConn.HandshakeContext(ctx) if err == nil { break } _ = tlsConn.Close() tlsConn = nil conn, err = defaultDialer.DialContext(ctx, network, net.JoinHostPort(a, port)) if err != nil { continue } tlsConn = tls.Client(terasu.NewConn(conn), cfg) err = tlsConn.HandshakeContext(ctx) if err == nil { break } _ = tlsConn.Close() tlsConn = nil } return tlsConn, err }, }, }
DefaultClient is the default HTTP2 client that supports HTTP/2 and DNS resolution
View Source
var ErrEmptyHostAddress = errors.New("empty host addr")
ErrEmptyHostAddress is returned when DNS lookup for a host returns no addresses
Functions ¶
func Post ¶
Post sends an HTTP POST request to the specified URL with the given content type and body using the default HTTP2 client
func PostForm ¶
PostForm sends an HTTP POST request with form data to the specified URL using the default HTTP2 client
func SetDefaultClientTimeout ¶
SetDefaultClientTimeout sets the default timeout for all HTTP2 client connections
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.