Documentation ¶
Overview ¶
Package httplib implements common utility functions for writing classic HTTP handlers
Package httplib implements common utility functions for writing classic HTTP handlers
Index ¶
- func ConvertResponse(re *roundtrip.Response, err error) (*roundtrip.Response, error)
- func MakeHandler(fn HandlerFunc) httprouter.Handle
- func MakeStdHandler(fn StdHandlerFunc) http.HandlerFunc
- func ParseBool(q url.Values, name string) (bool, bool, error)
- func ReadJSON(r *http.Request, val interface{}) error
- func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler
- func SafeRedirect(w http.ResponseWriter, r *http.Request, redirectURL string) error
- func SetIndexHTMLHeaders(h http.Header)
- func SetNoCacheHeaders(h http.Header)
- func SetNoSniff(h http.Header)
- func SetSameOriginIFrame(h http.Header)
- func SetStaticFileHeaders(h http.Header)
- func SetWebConfigHeaders(h http.Header)
- func WithCSRFProtection(fn HandlerFunc) httprouter.Handle
- type HandlerFunc
- type RewritePair
- type StdHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertResponse ¶
ConvertResponse converts http error to internal error type based on HTTP response code and HTTP body contents
func MakeHandler ¶
func MakeHandler(fn HandlerFunc) httprouter.Handle
MakeHandler returns a new httprouter.Handle func from a handler func
func MakeStdHandler ¶
func MakeStdHandler(fn StdHandlerFunc) http.HandlerFunc
MakeStdHandler returns a new http.Handle func from http.HandlerFunc
func RewritePaths ¶
func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler
RewritePaths creates a middleware that rewrites paths in incoming request
func SafeRedirect ¶
SafeRedirect performs a relative redirect to the URI part of the provided redirect URL
func SetIndexHTMLHeaders ¶
SetIndexHTMLHeaders sets security header flags for main index.html page
func SetNoCacheHeaders ¶
SetNoCacheHeaders tells proxies and browsers do not cache the content
func SetSameOriginIFrame ¶
SetSameOriginIFrame sets X-Frame-Options flag
func SetStaticFileHeaders ¶
SetStaticFileHeaders sets security header flags for static non-html resources
func SetWebConfigHeaders ¶
SetWebConfigHeaders sets headers for webConfig.js
func WithCSRFProtection ¶
func WithCSRFProtection(fn HandlerFunc) httprouter.Handle
WithCSRFProtection ensures that request to unauthenticated API is checked against CSRF attacks
Types ¶
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error)
HandlerFunc specifies HTTP handler function that returns error
type RewritePair ¶
type RewritePair struct { // Expr is matching expression Expr *regexp.Regexp // Replacement is replacement Replacement string }
RewritePair is a rewrite expression
func Rewrite ¶
func Rewrite(in, out string) RewritePair
Rewrite creates a rewrite pair, panics if in epxression is not a valid regular expressoin
type StdHandlerFunc ¶
type StdHandlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)
StdHandlerFunc specifies HTTP handler function that returns error