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 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.
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
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 ¶
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.