httputil

package
v0.0.0-...-a93040f Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: BSD-3-Clause Imports: 18 Imported by: 0

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

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 Error

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

type ResponseBuffer

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

func (*ResponseBuffer) Header

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

func (*ResponseBuffer) Write

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

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.

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