http

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GET  = DefaultClient.GET
	POST = DefaultClient.POST
)
View Source
var DefaultClient = NewClient(http.DefaultClient)

Functions

This section is empty.

Types

type Authorization

type Authorization interface {
	SetAuth(*http.Request)
}

func Basic

func Basic(username, password string) Authorization

func Bearer

func Bearer(token string) Authorization

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client is a fluent http.Client wrapper.

func NewClient

func NewClient(client *http.Client) *Client

NewClient wraps the passed http.Client. If http == nil, creates a new http.Client

func (*Client) AcceptStatus

func (c *Client) AcceptStatus(codes ...int) *Client

func (*Client) AddHeader

func (c *Client) AddHeader(key, value string) *Client

AddHeader allows to specify default header set to every request.

func (*Client) AddHeaders

func (c *Client) AddHeaders(kvPairs ...string) *Client

func (*Client) Auth

func (c *Client) Auth(auth Authorization) *Client

func (*Client) CONNECT

func (c *Client) CONNECT(resource string) *Request

func (*Client) DELETE

func (c *Client) DELETE(resource string) *Request

func (*Client) GET

func (c *Client) GET(resource string) *Request

func (*Client) HEAD

func (c *Client) HEAD(resource string) *Request

func (*Client) NewRequest

func (c *Client) NewRequest(method string, rawurl string) *Request

NewRequest creates a NewRequest.

func (*Client) OPTIONS

func (c *Client) OPTIONS(resource string) *Request

func (*Client) PATCH

func (c *Client) PATCH(resource string) *Request

func (*Client) POST

func (c *Client) POST(resource string) *Request

func (*Client) PUT

func (c *Client) PUT(resource string) *Request

func (*Client) SetCookies

func (c *Client) SetCookies(rawurl string, cookies ...*http.Cookie) *Client

SetCookies sets the http.Client cookies.

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string) *Client

func (*Client) SetHeaders

func (c *Client) SetHeaders(kvPairs ...string) *Client

func (*Client) TRACE

func (c *Client) TRACE(resource string) *Request

func (*Client) Timeout

func (c *Client) Timeout(timeout time.Duration) *Client

func (*Client) WithCookies

func (c *Client) WithCookies() *Client

type ContentType

type ContentType interface {
	ContentType() string
}

type ContentTypeError

type ContentTypeError string

func (ContentTypeError) Error

func (e ContentTypeError) Error() string

type Form

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

func (*Form) Add

func (f *Form) Add(key, value string) *Form

func (*Form) AddAll

func (f *Form) AddAll(key string, values ...string) *Form

func (*Form) AddValues

func (f *Form) AddValues(values url.Values) *Form

func (*Form) ContentType

func (*Form) ContentType() string

func (*Form) EncodeTo

func (f *Form) EncodeTo(writer io.Writer) error

func (*Form) Multipart

func (f *Form) Multipart() *MultipartForm

func (*Form) Set

func (f *Form) Set(key, value string) *Form

func (*Form) SetValues

func (f *Form) SetValues(values url.Values) *Form

func (*Form) Value

func (f *Form) Value(value interface{}) *Form

type MultipartForm

type MultipartForm struct {
	*Form
	// contains filtered or unexported fields
}

func NewMultipartForm

func NewMultipartForm() *MultipartForm

func (*MultipartForm) Add

func (mf *MultipartForm) Add(key, value string) *MultipartForm

func (*MultipartForm) AddAll

func (mf *MultipartForm) AddAll(keys string, values ...string) *MultipartForm

func (*MultipartForm) AddValues

func (mf *MultipartForm) AddValues(values url.Values) *MultipartForm

func (*MultipartForm) ContentType

func (mf *MultipartForm) ContentType() string

func (*MultipartForm) EncodeTo

func (mf *MultipartForm) EncodeTo(w io.Writer) error

func (*MultipartForm) File

func (mf *MultipartForm) File(fieldname, filename string, input flu.Input) *MultipartForm

func (*MultipartForm) Set

func (mf *MultipartForm) Set(key, value string) *MultipartForm

func (*MultipartForm) SetValues

func (mf *MultipartForm) SetValues(values url.Values) *MultipartForm

func (*MultipartForm) Value

func (mf *MultipartForm) Value(value interface{}) *MultipartForm

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request allows to set basic http.Request properties.

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

AddHeader adds a request header.

func (*Request) AddHeaders

func (r *Request) AddHeaders(kvPairs ...string) *Request

AddHeaders adds request header. kvPairs is an array of key-value pairs and must have even length.

func (*Request) Auth

func (r *Request) Auth(auth Authorization) *Request

func (*Request) BodyEncoder

func (r *Request) BodyEncoder(encoder flu.EncoderTo) *Request

func (*Request) BodyInput

func (r *Request) BodyInput(input flu.Input) *Request

func (*Request) ContentLength

func (r *Request) ContentLength(contentLength int64) *Request

func (*Request) ContentType

func (r *Request) ContentType(contentType string) *Request

func (*Request) Context

func (r *Request) Context(ctx context.Context) *Request

func (*Request) Execute

func (r *Request) Execute() *Response

Execute executes the request and returns a response.

func (*Request) QueryParam

func (r *Request) QueryParam(key, value string) *Request

QueryParam sets a query parameter.

func (*Request) QueryParams

func (r *Request) QueryParams(values url.Values) *Request

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

SetHeader sets a request header.

func (*Request) SetHeaders

func (r *Request) SetHeaders(kvPairs ...string) *Request

SetHeaders sets request header. kvPairs is an array of key-value pairs and must have even length.

func (*Request) URL

func (r *Request) URL(url *url.URL) *Request

type Response

type Response struct {
	*http.Response

	// Error contains an error in case of a request processing error
	// or nil in case of success.
	Error error
}

Response is a fluent response wrapper.

func (*Response) CheckContentType

func (r *Response) CheckContentType(value string) *Response

func (*Response) CheckStatus

func (r *Response) CheckStatus(codes ...int) *Response

CheckStatus checks the response status code and sets the error to StatusCodeError if there is no match.

func (*Response) DecodeBody

func (r *Response) DecodeBody(decoder flu.DecoderFrom) *Response

Decode reads the response body.

func (*Response) DecodeBodyTo

func (r *Response) DecodeBodyTo(out flu.Output) *Response

func (*Response) HandleResponse

func (r *Response) HandleResponse(handler ResponseHandler) *Response

HandleResponse executes a ResponseHandler if no previous handling errors occurred.

func (*Response) Reader

func (r *Response) Reader() (io.Reader, error)

type ResponseHandler

type ResponseHandler interface {
	Handle(*http.Response) error
}

type StatusCodeError

type StatusCodeError struct {
	StatusCode   int
	ResponseBody flu.Bytes
}

func NewStatusCodeError

func NewStatusCodeError(r *http.Response) StatusCodeError

func (StatusCodeError) Error

func (e StatusCodeError) Error() string

type Transport

type Transport struct {
	*http.Transport
	*net.Dialer
	// contains filtered or unexported fields
}

Transport is a fluent wrapper around *http.Transport.

func NewTransport

func NewTransport() *Transport

NewTransport initializes a new Transport with default settings. This should be equivalent to http.DefaultTransport

func (*Transport) DialContext

func (t *Transport) DialContext(fun func(ctx context.Context, network, addr string) (net.Conn, error)) *Transport

DialContext sets http.Transport.DialContext.

func (*Transport) DialTimeout

func (t *Transport) DialTimeout(timeout time.Duration) *Transport

func (*Transport) ExpectContinueTimeout

func (t *Transport) ExpectContinueTimeout(value time.Duration) *Transport

ExpectContinueTimeout sets http.Transport.ExpectContinueTimeout.

func (*Transport) ForceAttemptHTTP2

func (t *Transport) ForceAttemptHTTP2(allow bool) *Transport

func (*Transport) IdleConnTimeout

func (t *Transport) IdleConnTimeout(value time.Duration) *Transport

IdleConnTimeout sets http.Transport.IdleConnTimeout.

func (*Transport) MaxConnsPerHost

func (t *Transport) MaxConnsPerHost(value int) *Transport

MaxConnsPerHost sets http.Transport.MaxConnsPerHost.

func (*Transport) MaxIdleConns

func (t *Transport) MaxIdleConns(value int) *Transport

MaxIdleConns sets http.Transport.MaxIdleConns.

func (*Transport) MaxIdleConnsPerHost

func (t *Transport) MaxIdleConnsPerHost(value int) *Transport

MaxIdleConnsPerHost sets http.Transport.MaxIdleConnsPerHost.

func (*Transport) NewClient

func (t *Transport) NewClient() *Client

NewClient creates a new Client with this Transport.

func (*Transport) Proxy

func (t *Transport) Proxy(proxy func(*http.Request) (*url.URL, error)) *Transport

Proxy sets the http.Transport.Proxy.

func (*Transport) ProxyURL

func (t *Transport) ProxyURL(rawurl string) *Transport

func (*Transport) RateLimiter

func (t *Transport) RateLimiter(rateLimiter flu.RateLimiter) *Transport

func (*Transport) ResponseHeaderTimeout

func (t *Transport) ResponseHeaderTimeout(value time.Duration) *Transport

ResponseHeaderTimeout sets http.Transport.ResponseHeaderTimeout.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

func (*Transport) TLSClientConfig

func (t *Transport) TLSClientConfig(value *tls.Config) *Transport

func (*Transport) TLSHandshakeTimeout

func (t *Transport) TLSHandshakeTimeout(value time.Duration) *Transport

TLSHandshakeTimeout sets http.Transport.TLSHandshakeTimeout.

type VarargsLengthError

type VarargsLengthError int

func (VarargsLengthError) Error

func (e VarargsLengthError) Error() string

func (VarargsLengthError) Length

func (e VarargsLengthError) Length() int

Jump to

Keyboard shortcuts

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