Documentation
¶
Index ¶
- Variables
- func AssetServer(prefix, directory string) http.Handler
- func BasicAuth(username, password, realm string) func(http.Handler) http.Handler
- func CORS(policy CORSPolicy) func(http.Handler) http.Handler
- func Compose(chain ...interface{}) http.Handler
- func ContentSecurity(policy ContentPolicy) func(http.Handler) http.Handler
- func DataSize(str string) uint64
- func Hostname(host string) string
- func LimitBody(w http.ResponseWriter, r *http.Request, limit uint64)
- func Record(h http.Handler, method, url string, headers map[string]string, payload string) *httptest.ResponseRecorder
- func Secure(w http.ResponseWriter, r *http.Request, allowInsecure, noFrontend bool, ...) bool
- func Security(allowInsecure, noFrontend bool, stsMaxAge time.Duration) func(http.Handler) http.Handler
- type BodyLimiter
- type CORSPolicy
- type ContentPolicy
Constants ¶
This section is empty.
Variables ¶
var ErrBodyLimitExceeded = errors.New("body limit exceeded")
ErrBodyLimitExceeded is returned if a body is read beyond the set limit.
Functions ¶
func AssetServer ¶
AssetServer constructs an asset server handler that serves an asset directory on a specified path and serves the index file for not found paths which is needed to properly serve single page applications.
func CORS ¶
func CORS(policy CORSPolicy) func(http.Handler) http.Handler
CORS returns a middleware for enforcing CORS.
func ContentSecurity ¶
func ContentSecurity(policy ContentPolicy) func(http.Handler) http.Handler
ContentSecurity returns a middleware for enforcing content security.
func DataSize ¶
DataSize parses human readable data sizes (e.g. 4K, 20M or 5G) and returns the amount of bytes they represent.
func Hostname ¶ added in v0.1.3
Hostname will return the hostname from the provided host string. This method should be used instead of net.SplitHostPort when attempting to clean the http/Request.Host attribute.
func LimitBody ¶
func LimitBody(w http.ResponseWriter, r *http.Request, limit uint64)
LimitBody will limit reading from the body of the supplied request to the specified amount of bytes. Earlier calls to LimitBody will be overwritten which essentially allows callers to increase the limit from a default limit later in the request processing.
func Record ¶
func Record(h http.Handler, method, url string, headers map[string]string, payload string) *httptest.ResponseRecorder
Record will make a request against the specified handler and record the result.
func Secure ¶
func Secure(w http.ResponseWriter, r *http.Request, allowInsecure, noFrontend bool, stsMaxAge time.Duration) bool
Secure will enforce various common web security policies. It return whether the request is safe to be further processed. Subsequent handlers should update the headers with a more applicable content security policy.
Types ¶
type BodyLimiter ¶
type BodyLimiter struct {
Length int64
Limit uint64
Original io.ReadCloser
Limited io.ReadCloser
}
BodyLimiter wraps a io.ReadCloser and keeps a reference to the original.
func (*BodyLimiter) Close ¶ added in v0.2.0
func (l *BodyLimiter) Close() error
Close will close the body.
type ContentPolicy ¶
ContentPolicy for defining content security.
func (ContentPolicy) String ¶
func (p ContentPolicy) String() string
String will encode the policy as a string.