httputil

package
v0.0.0-...-20d68f9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: BSD-3-Clause Imports: 18 Imported by: 231

Documentation

Overview

Package httputil is a toolkit for the Go net/http package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NegotiateContentEncoding

func NegotiateContentEncoding(r *http.Request, offers []string) string

NegotiateContentEncoding returns the best offered content encoding for the request's Accept-Encoding header. If two offers match with equal weight and then the offer earlier in the list is preferred. If no offers are acceptable, then "" is returned.

func NegotiateContentType

func NegotiateContentType(r *http.Request, offers []string, defaultOffer string) string

NegotiateContentType returns the best offered content type for the request's Accept header. If two offers match with equal weight, then the more specific offer is preferred. For example, text/* trumps */*. If two offers match with equal weight and specificity, then the offer earlier in the list is preferred. If no offers match, then defaultOffer is returned.

func StripPort

func StripPort(s string) string

StripPort removes the port specification from an address.

Types

type AuthTransport

type AuthTransport struct {
	UserAgent          string
	GithubToken        string
	GithubClientID     string
	GithubClientSecret string
	Base               http.RoundTripper
}

AuthTransport is an implementation of http.RoundTripper that authenticates with the GitHub API.

When both a token and client credentials are set, the latter is preferred.

func (*AuthTransport) CancelRequest

func (t *AuthTransport) CancelRequest(req *http.Request)

CancelRequest cancels an in-flight request by closing its connection.

func (*AuthTransport) RoundTrip

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

RoundTrip implements the http.RoundTripper interface.

type CacheBusters

type CacheBusters struct {
	Handler http.Handler
	// contains filtered or unexported fields
}

CacheBusters maintains a cache of cache busting tokens for static resources served by Handler.

func (*CacheBusters) AppendQueryParam

func (cb *CacheBusters) AppendQueryParam(path string, name string) string

AppendQueryParam appends the token as a query parameter to path.

func (*CacheBusters) Get

func (cb *CacheBusters) Get(path string) string

Get returns the cache busting token for path. If the token is not already cached, Get issues a HEAD request on handler and uses the response ETag and Last-Modified headers to compute a token.

type Error

type Error func(w http.ResponseWriter, r *http.Request, status int, err error)

Error defines a type for a function that accepts a ResponseWriter for a Request with the HTTP status code and error.

type ResponseBuffer

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

ResponseBuffer is the current response being composed by its owner. It implements http.ResponseWriter and io.WriterTo.

func (*ResponseBuffer) Header

func (rb *ResponseBuffer) Header() http.Header

Header implements the http.ResponseWriter interface.

func (*ResponseBuffer) Write

func (rb *ResponseBuffer) Write(p []byte) (int, error)

Write implements the http.ResponseWriter interface.

func (*ResponseBuffer) WriteHeader

func (rb *ResponseBuffer) WriteHeader(status int)

WriteHeader implements the http.ResponseWriter interface.

func (*ResponseBuffer) WriteTo

func (rb *ResponseBuffer) WriteTo(w http.ResponseWriter) error

WriteTo implements the io.WriterTo interface.

type StaticServer

type StaticServer struct {
	// Dir specifies the location of the directory containing the files to serve.
	Dir string

	// MaxAge specifies the maximum age for the cache control and expiration
	// headers.
	MaxAge time.Duration

	// Error specifies the function used to generate error responses. If Error
	// is nil, then http.Error is used to generate error responses.
	Error Error

	// MIMETypes is a map from file extensions to MIME types.
	MIMETypes map[string]string
	// contains filtered or unexported fields
}

StaticServer serves static files.

func (*StaticServer) DirectoryHandler

func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler

DirectoryHandler returns a handler that serves files from a directory tree. The directory is specified by a slash separated path relative to the static server's Dir field.

func (*StaticServer) FileHandler

func (ss *StaticServer) FileHandler(fileName string) http.Handler

FileHandler returns a handler that serves a single file. The file is specified by a slash separated path relative to the static server's Dir field.

func (*StaticServer) FilesHandler

func (ss *StaticServer) FilesHandler(fileNames ...string) http.Handler

FilesHandler returns a handler that serves the concatentation of the specified files. The files are specified by slash separated paths relative to the static server's Dir field.

Directories

Path Synopsis
Package header provides functions for parsing HTTP headers.
Package header provides functions for parsing HTTP headers.

Jump to

Keyboard shortcuts

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