middleware

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = &Logger{
	Output: os.Stdout,
}

Functions

func AllowedHosts

func AllowedHosts(allowed_hosts ...string) func(next mux.Handler) mux.Handler

Check if the request.Host is in the allowed hosts list

func Cache

func Cache(maxAge int) func(next mux.Handler) mux.Handler

Set the cache headers for the response. This will enable caching for the specified amount of seconds.

func GZIP

func GZIP(next mux.Handler) mux.Handler

GZIP compresses the response using gzip compression.

func NoCache

func NoCache(next mux.Handler) mux.Handler

Set the cache headers for the response. This will disable caching.

func Recoverer

func Recoverer(onError func(err error, w http.ResponseWriter, r *http.Request)) mux.Middleware

Recoverer recovers from panics and logs the error, if the logger was set.

func XFrameOptions

func XFrameOptions(options XFrameOption) mux.Middleware

X-Frame-Options is a header that can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>.

Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

Types

type Logger added in v1.1.7

type Logger struct {
	Output         io.Writer
	RequestProxied bool
}

func (*Logger) Intercept added in v1.1.7

func (l *Logger) Intercept(next mux.Handler) mux.Handler

type XFrameOption

type XFrameOption string

XFrameOption is the type for the XFrameOptions middleware.

const (
	// XFrameDeny is the most restrictive option, and it tells the browser to not display the content in an iframe.
	XFrameDeny XFrameOption = "DENY"
	// XFrameSame is the default value for XFrameOptions.
	XFrameSame XFrameOption = "SAMEORIGIN"
	// XFrameAllow is a special case, and it should not be used.
	// It is obsolete and is only here for backwards compatibility.
	XFrameAllow XFrameOption = "ALLOW-FROM"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL