Documentation ¶
Overview ¶
Package httputil provides utilities on top of the net/http package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Middleware ¶
Middleware is a chainable decorator for HTTP Handlers.
func Chain ¶
func Chain(outer Middleware, others ...Middleware) Middleware
Chain is a helper function for composing middlewares. Requests will traverse them in the order they're declared. That is, the first middleware is treated as the outermost middleware.
Chain is identical to the go-kit helper for Endpoint Middleware.
Example ¶
package main import ( "fmt" "net/http" "net/http/httptest" ) func main() { h := Chain( annotate("one"), annotate("two"), annotate("three"), )(myHandler()) srv := httptest.NewServer(h) defer srv.Close() resp, err := http.Get(srv.URL) if err != nil { panic(err) } defer resp.Body.Close() } func annotate(s string) Middleware { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Println("annotate: ", s) next.ServeHTTP(w, r) }) } } func myHandler() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { }) }
Output: annotate: one annotate: two annotate: three
type Option ¶
Option configures an HTTP Server.
func WithIdleTimeout ¶
WithIdleTimeout sets the IdleTimeout option
func WithReadHeaderTimeout ¶
WithReadHeaderTimeout sets the ReadHeaderTimeout option
func WithReadTimeout ¶
WithReadTimeout sets the ReadTimeout option
func WithTLSConfig ¶
WithTLSConfig allows overriding the default TLS Config in the call to NewServer.
func WithWriteTimeout ¶
WithWriteTimeout sets the WriteTimeout option