Documentation ¶
Overview ¶
Package handlers is a collection of handlers for use with Go's net/http package.
Index ¶
- Constants
- func CombinedLoggingHandler(out io.Writer, h http.Handler) http.Handler
- func CompressHandler(h http.Handler) http.Handler
- func ContentTypeHandler(h http.Handler, contentTypes ...string) http.Handler
- func HTTPMethodOverrideHandler(h http.Handler) http.Handler
- func LoggingHandler(out io.Writer, h http.Handler) http.Handler
- type MethodHandler
Constants ¶
const ( // HTTPMethodOverrideHeader is a commonly used // http header to override a request method. HTTPMethodOverrideHeader = "X-HTTP-Method-Override" // HTTPMethodOverrideFormKey is a commonly used // HTML form key to override a request method. HTTPMethodOverrideFormKey = "_method" )
Variables ¶
This section is empty.
Functions ¶
func CombinedLoggingHandler ¶
CombinedLoggingHandler return a http.Handler that wraps h and logs requests to out in Apache Combined Log Format.
See http://httpd.apache.org/docs/2.2/logs.html#combined for a description of this format.
LoggingHandler always sets the ident field of the log to -
func ContentTypeHandler ¶
ContentTypeHandler wraps and returns a http.Handler, validating the request content type is acompatible with the contentTypes list. It writes a HTTP 415 error if that fails.
Only PUT, POST, and PATCH requests are considered.
func HTTPMethodOverrideHandler ¶
HTTPMethodOverrideHandler wraps and returns a http.Handler which checks for the X-HTTP-Method-Override header or the _method form key, and overrides (if valid) request.Method with its value.
This is especially useful for http clients that don't support many http verbs. It isn't secure to override e.g a GET to a POST, so only POST requests are considered. Likewise, the override method can only be a "write" method: PUT, PATCH or DELETE.
Form method takes precedence over header method.
func LoggingHandler ¶
LoggingHandler return a http.Handler that wraps h and logs requests to out in Apache Common Log Format (CLF).
See http://httpd.apache.org/docs/2.2/logs.html#common for a description of this format.
LoggingHandler always sets the ident field of the log to -
Types ¶
type MethodHandler ¶
MethodHandler is an http.Handler that dispatches to a handler whose key in the MethodHandler's map matches the name of the HTTP request's method, eg: GET
If the request's method is OPTIONS and OPTIONS is not a key in the map then the handler responds with a status of 200 and sets the Allow header to a comma-separated list of available methods.
If the request's method doesn't match any of its keys the handler responds with a status of 406, Method not allowed and sets the Allow header to a comma-separated list of available methods.
func (MethodHandler) ServeHTTP ¶
func (h MethodHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)