http

package
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 8

Documentation

Index

Constants

View Source
const (
	CSPHashSHA256 CSPHashAlgo = "sha256"
	CSPHashSHA384 CSPHashAlgo = "sha384"
	CSPHashSHA512 CSPHashAlgo = "sha512"

	CSPSrcNone           CSPSourceValue = "'none'"
	CSPSrcReportSample   CSPSourceValue = "'report-sample'"
	CSPSrcSelf           CSPSourceValue = "'self'"
	CSPSrcStrictDynamic  CSPSourceValue = "'strict-dynamic'"
	CSPSrcUnsafeEval     CSPSourceValue = "'unsafe-eval'"
	CSPSrcUnsafeHashes   CSPSourceValue = "'unsafe-hashes'"
	CSPSrcUnsafeInline   CSPSourceValue = "'unsafe-inline'"
	CSPSrcWASMUnsafeEval CSPSourceValue = "'wasm-unsafe-eval'"

	CSPSrcSchemeData        CSPSourceValue = "data:"
	CSPSrcSchemeMediastream CSPSourceValue = "mediastream:"
	CSPSrcSchemeBlob        CSPSourceValue = "blob:"
	CSPSrcSchemeFilesystem  CSPSourceValue = "filesystem:"
)

Collection of pre-defined values. For documentation see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources

Variables

This section is empty.

Functions

func GetDigestAuth

func GetDigestAuth(resp *http.Response, method, requestPath, user, password string) string

func GzipFunc

func GzipFunc(f http.HandlerFunc) http.HandlerFunc

GzipFunc wraps an http.HandlerFunc and gzips responses if the client supports it

func GzipHandler

func GzipHandler(handler http.Handler) http.Handler

GzipHandler wraps an http.Handler and gzips responses if the client supports it

func NewHTTPLogHandler

func NewHTTPLogHandler(h http.Handler) http.Handler

func NewHTTPLogHandlerWithLogger added in v2.12.0

func NewHTTPLogHandlerWithLogger(h http.Handler, l logrus.StdLogger) http.Handler

Types

type CSP added in v2.20.0

type CSP map[string][]CSPSourceValue

CSP is a non-concurrency-safe map to hold a Content-Security-Policy and manipulate it afterwards to eventually render it into its header-representation

func (CSP) Add added in v2.20.0

func (c CSP) Add(directive string, value CSPSourceValue)

Add adds a single CSPSourceValue to the given directive

func (CSP) Clone added in v2.20.0

func (c CSP) Clone() CSP

Clone copies the CSP into a new one for manipulation

func (CSP) Set added in v2.20.0

func (c CSP) Set(directive string, value CSPSourceValue)

Set replaces all present values for the given directive

func (CSP) ToHeaderValue added in v2.20.0

func (c CSP) ToHeaderValue() string

ToHeaderValue encodes the policy into the format expected in the `Content-Security-Policy` header.

type CSPHashAlgo added in v2.20.0

type CSPHashAlgo string

CSPHashAlgo defines the available hash algorithms

type CSPSourceValue added in v2.20.0

type CSPSourceValue string

CSPSourceValue represents an value in the map for a given directive

func CSPSrcHash added in v2.20.0

func CSPSrcHash(algo CSPHashAlgo, sum []byte) CSPSourceValue

CSPSrcHash takes an algo (sha256, sha384 or sha512) and the sum value and converts it into the right representation for the header

func CSPSrcNonce added in v2.20.0

func CSPSrcNonce(b64Value string) CSPSourceValue

CSPSrcNonce takes a base64 encoded nonce value and converts it into the right representation for the header

type HTTPLogHandler

type HTTPLogHandler struct {
	Handler          http.Handler
	TrustedIPHeaders []string
	// contains filtered or unexported fields
}

func (HTTPLogHandler) ServeHTTP

func (l HTTPLogHandler) ServeHTTP(res http.ResponseWriter, r *http.Request)

type LogRoundTripper added in v2.15.0

type LogRoundTripper struct {
	// contains filtered or unexported fields
}

LogRoundTripper is a drop-in for the Transport of a http.Client which then will log requests and responses to the given writer (os.Stdout / os.Stderr / logrus writer / ...)

func NewLogRoundTripper added in v2.15.0

func NewLogRoundTripper(next http.RoundTripper, out io.Writer) LogRoundTripper

NewLogRoundTripper creates a new LogRoundTripper with the given next transport and output writer. If no next transport is given (next == nil) the http.DefaultTransport is used. If no writer is given the io.Discard writer is used.

func (LogRoundTripper) RoundTrip added in v2.15.0

func (l LogRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper interface

type NoListFS added in v2.19.0

type NoListFS struct{ Next http.FileSystem }

NoListFS wraps an http.FileSystem and ensures no directory listings are printed out in order not to expose the contents of the directory in a listing.

func (NoListFS) Open added in v2.19.0

func (n NoListFS) Open(name string) (http.File, error)

Open wraps the Open of the inner http.FileSystem and returns an os.ErrNotExist in case a directory should be opened. This will result in a HTTP 404 when trying to open a directory causing the contents to be conceiled in an effective manner (zero exposure of known paths)

Jump to

Keyboard shortcuts

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