httpx

package
v0.0.0-...-0662ccb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2019 License: Apache-2.0 Imports: 17 Imported by: 10

Documentation

Index

Constants

View Source
const ResponseBodyAllSize int64 = 0

Variables

View Source
var (
	DefaultClient = NewClient()

	DefaultTransport = &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 60 * time.Second,
		}).DialContext,
		DisableKeepAlives:     false,
		MaxIdleConns:          http.DefaultTransport.(*http.Transport).MaxIdleConns,
		MaxIdleConnsPerHost:   http.DefaultMaxIdleConnsPerHost,
		IdleConnTimeout:       120 * time.Second,
		TLSHandshakeTimeout:   http.DefaultTransport.(*http.Transport).TLSHandshakeTimeout,
		ExpectContinueTimeout: http.DefaultTransport.(*http.Transport).ExpectContinueTimeout,
	}

	DefaultPool = &sync.Pool{
		New: func() interface{} {
			return bytes.NewBuffer(make([]byte, 0, 200<<10))
		},
	}
)

Functions

func GetFdWith

func GetFdWith(ctx context.Context, fd *os.File, path string, query url.Values, headers map[string][]string) error

func GetFile

func GetFile(ctx context.Context, save string, path string, query url.Values, headers map[string][]string) error

Types

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *HttpClient

func NewWithClient

func NewWithClient(client *http.Client) *HttpClient

func (*HttpClient) Close

func (client *HttpClient) Close()

func (*HttpClient) Delete

func (client *HttpClient) Delete(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) Get

func (client *HttpClient) Get(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) GetFdWith

func (client *HttpClient) GetFdWith(ctx context.Context, fd *os.File, path string, query url.Values, headers map[string][]string) error

func (*HttpClient) GetFile

func (client *HttpClient) GetFile(ctx context.Context, save string, path string, query url.Values, headers map[string][]string) error

func (*HttpClient) GetTransport

func (client *HttpClient) GetTransport() *http.Transport

func (*HttpClient) Head

func (client *HttpClient) Head(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) Options

func (client *HttpClient) Options(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) Patch

func (client *HttpClient) Patch(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PatchJSON

func (client *HttpClient) PatchJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PatchXML

func (client *HttpClient) PatchXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) Post

func (client *HttpClient) Post(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PostJSON

func (client *HttpClient) PostJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PostXML

func (client *HttpClient) PostXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) Put

func (client *HttpClient) Put(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PutJSON

func (client *HttpClient) PutJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) PutXML

func (client *HttpClient) PutXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpClient) RawClient

func (client *HttpClient) RawClient() *http.Client

func (*HttpClient) SetBasicAuth

func (client *HttpClient) SetBasicAuth(username string, password string) *HttpClient

func (*HttpClient) SetCookie

func (client *HttpClient) SetCookie(cookie *http.Cookie) *HttpClient

func (*HttpClient) SetCookies

func (client *HttpClient) SetCookies(cookies []*http.Cookie) *HttpClient

func (*HttpClient) SetHeader

func (client *HttpClient) SetHeader(key string, value string) *HttpClient

func (*HttpClient) SetHeaders

func (client *HttpClient) SetHeaders(headers map[string]string) *HttpClient

func (*HttpClient) SetProxy

func (client *HttpClient) SetProxy(proxy *url.URL) *HttpClient

func (*HttpClient) SetSocks5

func (client *HttpClient) SetSocks5(network string, addr string, auth *proxy.Auth, forward proxy.Dialer) *HttpClient

func (*HttpClient) SetTLSClientConfig

func (client *HttpClient) SetTLSClientConfig(tlsConfig *tls.Config) *HttpClient

func (*HttpClient) SetTransport

func (client *HttpClient) SetTransport(transport *http.Transport) *HttpClient

func (*HttpClient) UsePool

func (client *HttpClient) UsePool(pool *sync.Pool) *HttpClient

type HttpRequest

type HttpRequest struct {
	Method  string
	RawURL  string
	Query   url.Values
	Data    io.Reader
	Headers map[string][]string
}

type HttpResponse

type HttpResponse struct {
	// contains filtered or unexported fields
}

func Delete

func Delete(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func Get

func Get(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)
func Head(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func Options

func Options(ctx context.Context, path string, query url.Values, headers map[string][]string) (*HttpResponse, error)

func Patch

func Patch(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func PatchJSON

func PatchJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func PatchXML

func PatchXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func Post

func Post(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func PostJSON

func PostJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func PostXML

func PostXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func Put

func Put(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*HttpResponse, error)

func PutJSON

func PutJSON(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func PutXML

func PutXML(ctx context.Context, path string, query url.Values, object interface{}, headers map[string][]string) (*HttpResponse, error)

func (*HttpResponse) Body

func (resp *HttpResponse) Body() io.ReadCloser

func (*HttpResponse) Bytes

func (resp *HttpResponse) Bytes() ([]byte, error)

func (*HttpResponse) Close

func (resp *HttpResponse) Close() error

func (*HttpResponse) Header

func (resp *HttpResponse) Header(key string) string

func (*HttpResponse) Headers

func (resp *HttpResponse) Headers() http.Header

func (*HttpResponse) JSON

func (resp *HttpResponse) JSON(object interface{}) error

func (*HttpResponse) JSONMapper

func (resp *HttpResponse) JSONMapper(data interface{}) error

func (*HttpResponse) RawURL

func (resp *HttpResponse) RawURL() string

func (*HttpResponse) Status

func (resp *HttpResponse) Status() string

func (*HttpResponse) StatusCode

func (resp *HttpResponse) StatusCode() int

func (*HttpResponse) String

func (resp *HttpResponse) String() string

func (*HttpResponse) XML

func (resp *HttpResponse) XML(object interface{}) error

func (*HttpResponse) XMLMapper

func (resp *HttpResponse) XMLMapper(data interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL