httpcli

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCodec   = codecs.ByMediaType[codecs.MediaTypeProtobuf]
	DefaultHeaders = http.Header{}

	// DefaultConfigOpt represents the default client config options.
	DefaultConfigOpt = []ConfigOpt{
		Transport(func(t *http.Transport) {

			t.ResponseHeaderTimeout = 15 * time.Second
			t.MaxIdleConnsPerHost = 2
		}),
	}

	DefaultErrorMapper = ErrorMapperFunc(apierrors.FromResponse)
)

Functions

This section is empty.

Types

type Client

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

A Client is a Mesos HTTP APIs client.

func New

func New(opts ...Opt) *Client

New returns a new Client with the given Opts applied. Callers are expected to configure the URL, Do, and Codec options prior to invoking Do.

func (*Client) Do

func (c *Client) Do(m encoding.Marshaler, opt ...RequestOpt) (res mesos.Response, err error)

Do is deprecated in favor of Send.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the current Mesos API endpoint URL that the caller is set to invoke

func (*Client) HandleResponse

func (c *Client) HandleResponse(res *http.Response, rc client.ResponseClass, err error) (mesos.Response, error)

HandleResponse parses an HTTP response from a Mesos service endpoint, transforming the raw HTTP response into a mesos.Response.

func (*Client) Mesos

func (c *Client) Mesos(opts ...RequestOpt) mesos.Client

Mesos returns a mesos.Client variant backed by this implementation. Deprecated.

func (*Client) Send

func (c *Client) Send(cr client.Request, rc client.ResponseClass, opt ...RequestOpt) (res mesos.Response, err error)

Send sends a Call and returns (a) a Response (should be closed when finished) that contains a either a streaming or non-streaming Decoder from which callers can read objects from, and; (b) an error in case of failure. Callers are expected to *always* close a non-nil Response if one is returned. For operations which are successful but also for which there are no expected result objects the embedded Decoder will be nil. The provided ResponseClass determines whether the client implementation will attempt to decode a result as a single obeject or as an object stream. When working with versions of Mesos prior to v1.2.x callers MUST use ResponseClassAuto.

func (*Client) With

func (c *Client) With(opts ...Opt) Opt

With applies the given Opts to a Client and returns itself.

func (*Client) WithTemporary

func (c *Client) WithTemporary(opt Opt, f func() error) error

WithTemporary configures the Client with the temporary option and returns the results of invoking f(). Changes made to the Client by the temporary option are reverted before this func returns.

type Config

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

type ConfigOpt

type ConfigOpt func(*Config)

func BasicAuth

func BasicAuth(username, passwd string) ConfigOpt

BasicAuth generates a functional config option that sets HTTP Basic authentication for a Client

func RoundTripper

func RoundTripper(rt http.RoundTripper) ConfigOpt

RoundTripper returns a ConfigOpt that sets a Config's round-tripper.

func TLSConfig

func TLSConfig(tc *tls.Config) ConfigOpt

TLSConfig returns a ConfigOpt that sets a Config's TLS configuration.

func Timeout

func Timeout(d time.Duration) ConfigOpt

Timeout returns an ConfigOpt that sets a Config's response header timeout, tls handshake timeout, and dialer timeout.

func Transport

func Transport(modifyTransport func(*http.Transport)) ConfigOpt

Transport returns a ConfigOpt that allows tweaks of the default Config's http.Transport

func WrapRoundTripper

func WrapRoundTripper(f func(http.RoundTripper) http.RoundTripper) ConfigOpt

WrapRoundTripper allows a caller to customize a configuration's HTTP exchanger. Useful for authentication protocols that operate over stock HTTP.

type DoFunc

type DoFunc func(*http.Request) (*http.Response, error)

DoFunc sends an HTTP request and returns an HTTP response.

An error is returned if caused by client policy (such as http.Client.CheckRedirect), or if there was an HTTP protocol error. A non-2xx response doesn't cause an error.

When err is nil, resp always contains a non-nil resp.Body.

Callers should close resp.Body when done reading from it. If resp.Body is not closed, an underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

The request Body, if non-nil, will be closed by an underlying Transport, even on errors.

func With

func With(opt ...ConfigOpt) DoFunc

With returns a DoFunc that executes HTTP round-trips. The default implementation provides reasonable defaults for timeouts: keep-alive, connection, request/response read/write, and TLS handshake. Callers can customize configuration by specifying one or more ConfigOpt's.

type ErrorMapperFunc

type ErrorMapperFunc func(*http.Response) error

ErrorMapperFunc generates an error for the given response.

type HTTPRequestHelper

type HTTPRequestHelper struct {
	*http.Request
}

HTTPRequestHelper wraps an http.Request and provides utility funcs to simplify code elsewhere

type Opt

type Opt func(*Client) Opt

Opt defines a functional option for the HTTP client type. A functional option must return an Opt that acts as an "undo" if applied to the same Client.

func Codec

func Codec(codec encoding.Codec) Opt

Codec returns an Opt that sets a Client's Codec.

func DefaultHeader

func DefaultHeader(k, v string) Opt

DefaultHeader returns an Opt that adds a header to an Client's headers.

func Do

func Do(do DoFunc) Opt

Do returns an Opt that sets a Client's DoFunc

func Endpoint

func Endpoint(rawurl string) Opt

Endpoint returns an Opt that sets a Client's URL.

func ErrorMapper

func ErrorMapper(em ErrorMapperFunc) Opt

ErrorMapper returns am Opt that overrides the existing error mapping behavior of the client.

func HandleResponse

func HandleResponse(f ResponseHandler) Opt

HandleResponse returns a functional config option to set the HTTP response handler of the client.

func RequestOptions

func RequestOptions(opts ...RequestOpt) Opt

RequestOptions returns an Opt that applies the given set of options to every Client request.

func WrapDoer

func WrapDoer(f func(DoFunc) DoFunc) Opt

WrapDoer returns an Opt that decorates a Client's DoFunc

func (Opt) And

func (o Opt) And(other Opt) Opt

And combines two functional options into a single Opt

func (Opt) Apply

func (o Opt) Apply(c *Client) (result Opt)

Apply is a nil-safe application of an Opt: if the receiver is nil then this func simply returns nil, otherwise it returns the result invoking the receiving Opt with the given Client.

type Opts

type Opts []Opt

Opts represents a series of functional options

func (Opts) Merged

func (opts Opts) Merged() Opt

Merged generates a single Opt that applies all the functional options, in-order

type ProtocolError

type ProtocolError string

ProtocolError is returned when we receive a response from Mesos that is outside of the HTTP API specification. Receipt of the following will yield protocol errors:

  • any unexpected non-error HTTP response codes (e.g. 199)
  • any unexpected Content-Type

func (ProtocolError) Error

func (pe ProtocolError) Error() string

Error implements error interface

type RequestOpt

type RequestOpt func(*http.Request)

RequestOpt defines a functional option for an http.Request.

func Close

func Close(b bool) RequestOpt

Close returns a RequestOpt that determines whether to close the underlying connection after sending the request.

func Context

func Context(ctx context.Context) RequestOpt

Context returns a RequestOpt that sets the request's Context (ctx must be non-nil)

func Header(k, v string) RequestOpt

Header returns an RequestOpt that adds a header value to an HTTP requests's header.

type RequestOpts

type RequestOpts []RequestOpt

RequestOpts is a convenience type

func (RequestOpts) Apply

func (opts RequestOpts) Apply(req *http.Request)

Apply this set of request options to the given HTTP request.

type Response

type Response struct {
	io.Closer
	encoding.Decoder
	Header http.Header
}

Response captures the output of a Mesos HTTP API operation. Callers are responsible for invoking Close when they're finished processing the response otherwise there may be connection leaks.

type ResponseHandler

type ResponseHandler func(*http.Response, client.ResponseClass, error) (mesos.Response, error)

ResponseHandler is invoked to process an HTTP response. Callers SHALL invoke Close for a non-nil Response, even when errors are returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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