Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var RedirectStatusCode = http.StatusMovedPermanently
Functions ¶
func Redirect ¶
func Redirect(rules ...IgnoreRule) xun.Middleware
Redirect is a middleware that redirects plain HTTP requests to HTTPS.
func WriteHeader ¶
func WriteHeader(opts ...Option) xun.Middleware
WriteHeader is a middleware that sets the STS response header for a HTTPs request.
Types ¶
type Config ¶
type Config struct {
MaxAge int64 // MaxAge specifies the duration for which the HSTS policy is in effect.
IncludeSubDomains bool // IncludeSubDomains indicates whether the HSTS policy applies to subdomains.
Preload bool // Preload indicates whether the domain should be preloaded into browsers' HSTS lists.
}
Config represents the configuration options for HSTS (HTTP Strict Transport Security). It includes various settings such as MaxAge, IncludeSubDomains, and Preload.
type IgnoreRule ¶ added in v1.1.1
IgnoreRule is a function that takes a pointer to an http.Request and returns a boolean indicating whether the request should be ignored by the HSTS middleware.
func Match ¶ added in v1.1.1
func Match(paths ...string) IgnoreRule
Match creates an IgnoreRule that matches the given paths to ignore requests.
The paths are matched case-insensitively, so "/Doc" and "/doc" would be equivalent.
func StartsWith ¶ added in v1.1.1
func StartsWith(paths ...string) IgnoreRule
StartsWith creates an IgnoreRule that checks if the request path starts with any of the specified prefixes.
The provided paths are automatically converted to lower-case for consistent matching.
type Option ¶
type Option func(c *Config)
Option is a function that modifies a Config instance. It is used to configure HSTS settings by applying various options.
func WithIncludeSubDomains ¶
func WithIncludeSubDomains() Option
WithIncludeSubDomains sets the HSTS policy applies to subdomains.
func WithMaxAge ¶
WithMaxAge sets the maximum age for the HSTS policy.
The maximum age specifies the duration for which the HSTS policy is in effect. Note that the maximum age is specified in seconds, so "1h" would be equivalent to 3600.
func WithPreload ¶
func WithPreload() Option
WithPreload sets the domain should be preloaded into browsers' HSTS lists.