httputil

package
v0.0.0-...-cfd7a7c Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodePathSegment

func EncodePathSegment(s string) string

Percent-encode the supplied string so that it matches the grammar laid out for the 'segment' category in RFC 3986.

func NewRequest

func NewRequest(
	ctx context.Context,
	method string,
	url *url.URL,
	body io.ReadCloser,
	bodyLength int64,
	userAgent string) (req *http.Request, err error)

Create an HTTP request with the supplied information. bodyLength must be the total amount of data that will be returned by body, or -1 if unknown.

Unlike http.NewRequest:

  • This function configures the request to be cancelled when the supplied context is.

  • This function doesn't mangle the supplied URL by round tripping it to a string. For example, the Opaque field will continue to differentiate between actual slashes in the path and escaped ones (cf. http://goo.gl/rWX6ps).

  • This function contains less magic: it insists on an io.ReadCloser as in http.Request.Body, and doesn't attempt to imperfectly sniff content length.

  • This function provides a convenient choke point to ensure we don't forget to set a user agent header.

Types

type CancellableRoundTripper

type CancellableRoundTripper interface {
	http.RoundTripper
	CancelRequest(*http.Request)
}

An interface for transports that support the signature of http.Transport.CancelRequest.

func DebuggingRoundTripper

func DebuggingRoundTripper(
	in CancellableRoundTripper,
	logger *log.Logger) (out CancellableRoundTripper)

Wrap the supplied round tripper in a layer that dumps information about HTTP requests. unmodified.

type ContentTypedReader

type ContentTypedReader struct {
	ContentType string
	Reader      io.Reader
}

type MultipartReader

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

MultipartReader is an io.Reader that generates HTTP multipart bodies. See NewMultipartReader for details.

func NewMultipartReader

func NewMultipartReader(ctrs []ContentTypedReader) *MultipartReader

Create a reader that streams an HTTP multipart body (see RFC 2388) composed of the contents of each component reader in sequence, each with a Content-Type header as specified.

Unlike multipart.Writer from the standard library, this can be used directly as http.Request.Body without bending over backwards to convert an io.Writer to an io.Reader.

func (*MultipartReader) ContentType

func (mr *MultipartReader) ContentType() string

Return the value to use for the Content-Type header in an HTTP request that uses mr as the body.

func (*MultipartReader) Read

func (mr *MultipartReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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