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 ¶
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 ¶
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.
Types ¶
type AuthTransport ¶
type AuthTransport struct { UserAgent string Token string ClientID string ClientSecret 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 NewAuthTransport ¶
func NewAuthTransport(base http.RoundTripper) *AuthTransport
NewAuthTransport gives new AuthTransport created with GitHub credentials read from GCE metadata when the metadata server is accessible (we're on GCE) or read from environment varialbes otherwise.
func NewAuthTransportFromEnvironment ¶
func NewAuthTransportFromEnvironment(base http.RoundTripper) *AuthTransport
NewAuthTransportFromEnvironment gives new AuthTransport created with GitHub credentials read from environment variables.
func NewAuthTransportFromMetadata ¶
func NewAuthTransportFromMetadata(base http.RoundTripper) *AuthTransport
NewAuthTransportFromMetadata gives new AuthTransport created with GitHub credentials read from GCE metadata.
func (*AuthTransport) CancelRequest ¶
func (c *AuthTransport) CancelRequest(req *http.Request)
CancelRequest cancels an in-flight request by closing its connection.
type CacheBusters ¶
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
Token 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 ResponseBuffer ¶
type ResponseBuffer struct {
// contains filtered or unexported fields
}
func (*ResponseBuffer) Header ¶
func (rb *ResponseBuffer) Header() http.Header
func (*ResponseBuffer) WriteHeader ¶
func (rb *ResponseBuffer) WriteHeader(status int)
func (*ResponseBuffer) WriteTo ¶
func (rb *ResponseBuffer) WriteTo(w http.ResponseWriter) error
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.