cockroach: github.com/cockroachdb/cockroach/pkg/util/httputil Index | Files

package httputil

import "github.com/cockroachdb/cockroach/pkg/util/httputil"

Index

Package Files

client.go http.go req_go113.go

Constants

const (
    // AcceptHeader is the canonical header name for accept.
    AcceptHeader = "Accept"
    // AcceptEncodingHeader is the canonical header name for accept encoding.
    AcceptEncodingHeader = "Accept-Encoding"
    // ContentEncodingHeader is the canonical header name for content type.
    ContentEncodingHeader = "Content-Encoding"
    // ContentTypeHeader is the canonical header name for content type.
    ContentTypeHeader = "Content-Type"
    // JSONContentType is the JSON content type.
    JSONContentType = "application/json"
    // AltJSONContentType is the alternate JSON content type.
    AltJSONContentType = "application/x-json"
    // ProtoContentType is the protobuf content type.
    ProtoContentType = "application/x-protobuf"
    // AltProtoContentType is the alternate protobuf content type.
    AltProtoContentType = "application/x-google-protobuf"
    // PlaintextContentType is the plaintext content type.
    PlaintextContentType = "text/plain"
    // GzipEncoding is the gzip encoding.
    GzipEncoding = "gzip"
)

Variables

var DefaultClient = NewClientWithTimeout(standardHTTPTimeout)

DefaultClient is a replacement for http.DefaultClient which defines a standard timeout.

func Get Uses

func Get(ctx context.Context, url string) (resp *http.Response, err error)

Get does like http.Get but uses the provided context and obeys its cancellation. It also uses the default client with a default 3 second timeout.

func GetJSON Uses

func GetJSON(httpClient http.Client, path string, response protoutil.Message) error

GetJSON uses the supplied client to GET the URL specified by the parameters and unmarshals the result into response. TODO(someone): make this context-aware, see client.go.

func Head(ctx context.Context, url string) (resp *http.Response, err error)

Head does like http.Head but uses the provided context and obeys its cancellation. It also uses the default client with a default 3 second timeout.

func NewRequestWithContext Uses

func NewRequestWithContext(
    ctx context.Context, method, url string, body io.Reader,
) (*http.Request, error)

NewRequestWithContext aliases http.NewRequestWithContext. TODO(knz): this can be removed when the repo is upgraded to use go 1.13.

func Post Uses

func Post(
    ctx context.Context, url, contentType string, body io.Reader,
) (resp *http.Response, err error)

Post does like http.Post but uses the provided context and obeys its cancellation. It also uses the default client with a default 3 second timeout.

func PostJSON Uses

func PostJSON(httpClient http.Client, path string, request, response protoutil.Message) error

PostJSON uses the supplied client to POST request to the URL specified by the parameters and unmarshals the result into response. TODO(someone): make this context-aware, see client.go.

func PostJSONWithRequest Uses

func PostJSONWithRequest(
    httpClient http.Client, path string, request, response protoutil.Message,
) (*http.Response, error)

PostJSONWithRequest uses the supplied client to POST request to the URL specified by the parameters and unmarshals the result into response.

The response is returned to the caller, though its body will have been closed. TODO(someone): make this context-aware, see client.go.

type Client Uses

type Client struct {
    *http.Client
}

Client is a replacement for http.Client which implements method variants that respect a provided context's cancellation status.

func NewClientWithTimeout Uses

func NewClientWithTimeout(timeout time.Duration) *Client

NewClientWithTimeout defines a http.Client with the given timeout.

func (*Client) Get Uses

func (c *Client) Get(ctx context.Context, url string) (resp *http.Response, err error)

Get does like http.Client.Get but uses the provided context and obeys its cancellation.

func (*Client) Head Uses

func (c *Client) Head(ctx context.Context, url string) (resp *http.Response, err error)

Head does like http.Client.Head but uses the provided context and obeys its cancellation.

func (*Client) Post Uses

func (c *Client) Post(
    ctx context.Context, url, contentType string, body io.Reader,
) (resp *http.Response, err error)

Post does like http.Client.Post but uses the provided context and obeys its cancellation.

Package httputil imports 11 packages (graph) and is imported by 94 packages. Updated 2019-12-10. Refresh now. Tools for package owners.