gddo: github.com/golang/gddo/httputil Index | Files | Directories

package httputil

import "github.com/golang/gddo/httputil"

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

Index

Package Files

buster.go httputil.go negotiate.go respbuf.go static.go transport.go

func NegotiateContentEncoding Uses

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 Uses

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 Uses

func StripPort(s string) string

StripPort removes the port specification from an address.

type AuthTransport Uses

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 Uses

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

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

func (*AuthTransport) RoundTrip Uses

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

RoundTrip implements the http.RoundTripper interface.

type CacheBusters Uses

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 Uses

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

AppendQueryParam appends the token as a query parameter to path.

func (*CacheBusters) Get Uses

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 Uses

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 Uses

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 Uses

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

Header implements the http.ResponseWriter interface.

func (*ResponseBuffer) Write Uses

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

Write implements the http.ResponseWriter interface.

func (*ResponseBuffer) WriteHeader Uses

func (rb *ResponseBuffer) WriteHeader(status int)

WriteHeader implements the http.ResponseWriter interface.

func (*ResponseBuffer) WriteTo Uses

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

WriteTo implements the io.WriterTo interface.

type StaticServer Uses

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 Uses

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 Uses

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 Uses

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

PathSynopsis
headerPackage header provides functions for parsing HTTP headers.

Package httputil imports 18 packages (graph) and is imported by 138 packages. Updated 2018-11-18. Refresh now. Tools for package owners.