xmw

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	AccessLogStartKey = "X_ACCESS_START"
	AccessLogEndKey   = "X_ACCESS_END"
)
View Source
const (
	AuthCookieName             = "X_AUTH"
	AuthRedirectOriginURLQuery = "origin"
)
View Source
const (
	DigestAuthCtxKey = "X_DIGEST" // Key for digest parameters saved in context
	DigestAuthPrefix = "Digest "  // Digest Authentication Prefix
)
View Source
const (
	TokenAttrKey    = "X_TOKEN"
	TokenParamName  = "_token_"
	TokenHeaderName = "X-CSRF-TOKEN" //nolint: gosec
	TokenCookieName = "X_TOKEN"
)
View Source
const AccessLogJSONFormat = `` /* 191-byte string literal not displayed */

AccessLogJSONFormat default json log format

View Source
const AccessLogTextFormat = "text:%t\t%S\t%D\t%B\t%c\t%r\t%m\t%s://%h%u\t%h{User-Agent}%n"

AccessLogTextFormat default text log format TIME STATUS LATENCY SIZE CLIENT_IP REMOTE_ADDR METHOD HOST URL HEADER(User-Agent)

View Source
const AccessLogTimeFormat = "2006-01-02T15:04:05.000Z07:00"

AccessLogTimeFormat default log time format

View Source
const (
	AuthUserKey = "X_AUTH_USER" // Key for authenticated user object saved in context
)
View Source
const (
	BasicAuthPrefix = "Basic " // Basic Authentication Prefix
)
View Source
const (
	BearerAuthPrefix = "Bearer " // Bearer Authentication Prefix
)
View Source
const HTTPDumpKey = "X_DUMP"

HTTPDumpKey is the key for dump http saved in context

Variables

View Source
var (
	// LocaleParamNames default parameter key names
	LocaleParamNames = []string{"_locale_"}

	// LocaleCookieNames default cookie names
	LocaleCookieNames = []string{"X_LOCALE"}

	// LocaleHeaderNames default http header names
	LocaleHeaderNames = []string{"Accept-Language"}
)

Functions

This section is empty.

Types

type AccessLogJSONWriter added in v1.0.12

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

AccessLogJSONWriter format(json-style) and write access log

func NewAccessLogJSONWriter added in v1.0.12

func NewAccessLogJSONWriter(writer io.Writer, format string) *AccessLogJSONWriter

NewAccessLogJSONWriter create json style writer for AccessLogger

func (*AccessLogJSONWriter) SetFormat added in v1.0.12

func (aljw *AccessLogJSONWriter) SetFormat(format string)

SetFormat set the access alw format

func (*AccessLogJSONWriter) SetOutput added in v1.0.12

func (aljw *AccessLogJSONWriter) SetOutput(w io.Writer)

SetOutput set the access log writer

func (*AccessLogJSONWriter) Write added in v1.0.12

func (aljw *AccessLogJSONWriter) Write(c *xin.Context)

Write write the access log

type AccessLogMultiWriter added in v1.0.12

type AccessLogMultiWriter struct {
	Writers []AccessLogWriter
}

AccessLogMultiWriter write log to multiple writers.

func NewAccessLogMultiWriter added in v1.0.12

func NewAccessLogMultiWriter(ws ...AccessLogWriter) *AccessLogMultiWriter

NewAccessLogMultiWriter create a multi writer

func (*AccessLogMultiWriter) Write added in v1.0.12

func (mw *AccessLogMultiWriter) Write(c *xin.Context)

Write write the access log to multiple writers.

type AccessLogTextWriter added in v1.0.12

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

AccessLogTextWriter format(text) and write access log

func NewAccessLogTextWriter added in v1.0.12

func NewAccessLogTextWriter(writer io.Writer, format string) *AccessLogTextWriter

NewAccessLogTextWriter create text style writer for AccessLogger

func (*AccessLogTextWriter) SetFormat added in v1.0.12

func (altw *AccessLogTextWriter) SetFormat(format string)

SetFormat set the access alw format

func (*AccessLogTextWriter) SetOutput added in v1.0.12

func (altw *AccessLogTextWriter) SetOutput(w io.Writer)

SetOutput set the access log writer

func (*AccessLogTextWriter) Write added in v1.0.12

func (altw *AccessLogTextWriter) Write(c *xin.Context)

Write write the access log

type AccessLogWriter added in v1.0.12

type AccessLogWriter interface {
	Write(*xin.Context)
}

AccessLogWriter access log writer for XIN

%t{format} - Request start time, if {format} is omitted, '2006-01-02T15:04:05.000Z07:00' is used.
%c - Client IP ([X-Forwarded-For, X-Real-Ip] or RemoteIP())
%r - Remote IP:Port (%a)
%u - Request URL
%p - Request protocol
%s - Request scheme (http, https)
%m - Request method (GET, POST, etc.)
%q - Query string (prepended with a '?' if it exists)
%h - Request host
%h{name} - Request header
%A - Server listen address
%D - Time taken to process the request, duration format string
%T - Time taken to process the request, number in milliseconds
%S - Response status code
%B - Response body length (%L)
%H - Local hostname
%H{name} - Response header
%n: EOL(Windows: "\r\n", Other: "\n")

func NewAccessLogWriter added in v1.0.12

func NewAccessLogWriter(writer io.Writer, format string) AccessLogWriter

NewAccessLogWriter create a text or json access log writer text:... -> AccessLogTextWriter json:... -> AccessLogJSONWriter

type AccessLogger

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

AccessLogger access logger middleware for XIN

Example
router := xin.New()
router.Use(NewAccessLogger(NewAccessLogWriter(os.Stdout, AccessLogTextFormat)).Handle)

router.Any("/example", func(c *xin.Context) {
	c.String(http.StatusOK, c.Request.URL.String())
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/example?a=100", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultAccessLogger

func DefaultAccessLogger(xin *xin.Engine) *AccessLogger

DefaultAccessLogger create a access logger middleware for XIN Equals: NewAccessLogger(NewAccessLogTextWriter(xin.Logger.GetOutputer("XAL", log.LevelTrace), AccessLogTextFormat))

func NewAccessLogger

func NewAccessLogger(writer AccessLogWriter) *AccessLogger

NewAccessLogger create a log middleware for xin access logger

func (*AccessLogger) Disable

func (al *AccessLogger) Disable(disabled bool)

Disable disable the logger or not

func (*AccessLogger) Handle added in v1.0.10

func (al *AccessLogger) Handle(c *xin.Context)

Handle process xin request

func (*AccessLogger) SetWriter added in v1.0.12

func (al *AccessLogger) SetWriter(alw AccessLogWriter)

SetWriter set the access logger writer

type AuthUser added in v1.0.14

type AuthUser interface {
	GetUsername() string
	GetPassword() string
}

AuthUser a authenticated user interface

type BasicAuth

type BasicAuth struct {
	Realm       string
	FindUser    FindUserFunc
	AuthUserKey string
	AuthPassed  func(c *xin.Context, au AuthUser)
	AuthFailed  xin.HandlerFunc
}

BasicAuth basic http authenticator

func NewBasicAuth

func NewBasicAuth(f FindUserFunc) *BasicAuth

func (*BasicAuth) Authenticate added in v1.0.27

func (ba *BasicAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*BasicAuth) Handle added in v1.0.10

func (ba *BasicAuth) Handle(c *xin.Context)

Handle process xin request

func (*BasicAuth) Unauthorized added in v1.0.15

func (ba *BasicAuth) Unauthorized(c *xin.Context)

Unauthorized set basic authentication WWW-Authenticate header

type BearerAuth added in v1.0.27

type BearerAuth struct {
	Realm       string
	FindUser    FindUserFunc
	AuthUserKey string
	AuthPassed  func(c *xin.Context, au AuthUser)
	AuthFailed  xin.HandlerFunc
}

BearerAuth bearer http authenticator

func NewBearerAuth added in v1.0.27

func NewBearerAuth(f FindUserFunc) *BearerAuth

func (*BearerAuth) Authenticate added in v1.0.27

func (ba *BearerAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*BearerAuth) Handle added in v1.0.27

func (ba *BearerAuth) Handle(c *xin.Context)

Handle process xin request

func (*BearerAuth) Unauthorized added in v1.0.27

func (ba *BearerAuth) Unauthorized(c *xin.Context)

Unauthorized set bearer authentication WWW-Authenticate header

type Compressor added in v1.0.27

type Compressor interface {
	io.Writer
	Reset(w io.Writer)
	Flush() error
	Close() error
}

type CompressorProvider added in v1.0.27

type CompressorProvider interface {
	GetCompressor() Compressor
	PutCompressor(Compressor)
}

type CookieAuth added in v1.0.14

type CookieAuth struct {
	Cryptor        cpt.Cryptor // cryptor to encode/decode cookie, MUST concurrent safe
	FindUser       FindUserFunc
	AuthUserKey    string
	RedirectURL    string
	OriginURLQuery string
	AuthPassed     func(c *xin.Context, au AuthUser)
	AuthFailed     xin.HandlerFunc

	CookieName      string
	CookieMaxAge    time.Duration
	CookieDomain    string
	CookiePath      string
	CookieSecure    bool
	CookieHttpOnly  bool
	CookieSameSite  http.SameSite
	GetCookieMaxAge func(c *xin.Context) time.Duration
}

CookieAuth cookie authenticator

func NewCookieAuth added in v1.0.14

func NewCookieAuth(f FindUserFunc, secret string) *CookieAuth

func (*CookieAuth) Authenticate added in v1.0.27

func (ca *CookieAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*CookieAuth) BuildRedirectURL added in v1.0.27

func (ca *CookieAuth) BuildRedirectURL(c *xin.Context) string

func (*CookieAuth) DeleteCookie added in v1.0.14

func (ca *CookieAuth) DeleteCookie(c *xin.Context)

func (*CookieAuth) GetUserPassFromCookie added in v1.0.14

func (ca *CookieAuth) GetUserPassFromCookie(c *xin.Context) (username, password string, ok bool)

func (*CookieAuth) Handle added in v1.0.14

func (ca *CookieAuth) Handle(c *xin.Context)

Handle process xin request

func (*CookieAuth) SaveUserPassToCookie added in v1.0.14

func (ca *CookieAuth) SaveUserPassToCookie(c *xin.Context, au AuthUser) error

func (*CookieAuth) SetSecret added in v1.0.27

func (ca *CookieAuth) SetSecret(secret string)

SetSecret Set the Cryptor secret

func (*CookieAuth) Unauthorized added in v1.0.15

func (ca *CookieAuth) Unauthorized(c *xin.Context)

Unauthorized redirect or abort with status 401

type DigestAuth

type DigestAuth struct {
	Realm        string
	Opaque       string
	NonceExpires time.Duration
	FindUser     FindUserFunc
	AuthUserKey  string
	AuthPassed   func(c *xin.Context, au AuthUser)
	AuthFailed   xin.HandlerFunc
	// contains filtered or unexported fields
}

DigestAuth digest http authenticator

func NewDigestAuth

func NewDigestAuth(f FindUserFunc) *DigestAuth

func (*DigestAuth) Authenticate added in v1.0.27

func (da *DigestAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*DigestAuth) Handle added in v1.0.10

func (da *DigestAuth) Handle(c *xin.Context)

Handle process xin request

func (*DigestAuth) Unauthorized added in v1.0.15

func (da *DigestAuth) Unauthorized(c *xin.Context)

Unauthorized set WWW-Authenticate header

func (*DigestAuth) VerifyPassword added in v1.0.27

func (da *DigestAuth) VerifyPassword(c *xin.Context, password string) (bool, error)

type FindUserFunc added in v1.0.14

type FindUserFunc func(c *xin.Context, username, password string) (AuthUser, error)

FindUserFunc user lookup function

type GzipCompressorProvider added in v1.0.27

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

func NewGzipCompressorProvider added in v1.0.27

func NewGzipCompressorProvider() *GzipCompressorProvider

func (*GzipCompressorProvider) GetCompressor added in v1.0.27

func (gcws *GzipCompressorProvider) GetCompressor() Compressor

func (*GzipCompressorProvider) NewCompressor added in v1.0.27

func (gcws *GzipCompressorProvider) NewCompressor() any

func (*GzipCompressorProvider) PutCompressor added in v1.0.27

func (gcws *GzipCompressorProvider) PutCompressor(cw Compressor)

type HTTPDumper

type HTTPDumper struct {
	Outputer   io.Writer
	Maxlength  int64
	DumpCtxKey string // use xin.Context.Set(key, true | false) to enable/disable dump
	// contains filtered or unexported fields
}

HTTPDumper dump http request and response

Example
router := xin.New()
router.Use(NewHTTPDumper(os.Stdout).Handle)

router.Any("/example", func(c *xin.Context) {
	c.String(http.StatusOK, c.Request.URL.String())
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/example?a=100", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultHTTPDumper

func DefaultHTTPDumper(xin *xin.Engine) *HTTPDumper

DefaultHTTPDumper create a middleware for xin http dumper Equals: NewHTTPDumper(xin.Logger.Outputer("XHD", log.LevelTrace))

func NewHTTPDumper

func NewHTTPDumper(outputer io.Writer) *HTTPDumper

NewHTTPDumper create a middleware for xin http dumper

func (*HTTPDumper) Disable

func (hd *HTTPDumper) Disable(disabled bool)

Disable disable the dumper or not

func (*HTTPDumper) Handle added in v1.0.10

func (hd *HTTPDumper) Handle(c *xin.Context)

Handle process xin request

type HTTPSRedirector added in v1.0.14

type HTTPSRedirector struct {

	// If TemporaryRedirect is true, the a 302 will be used while redirecting. Default is false (301).
	TemporaryRedirect bool

	// SSLHost is the host name that is used to redirect http requests to https. Default is "", which indicates to use the same host.
	SSLHost string
	// contains filtered or unexported fields
}

HTTPSRedirector is a middleware that helps setup a https redirect features.

func NewHTTPSRedirector added in v1.0.14

func NewHTTPSRedirector() *HTTPSRedirector

func (*HTTPSRedirector) Disable added in v1.0.14

func (sh *HTTPSRedirector) Disable(disabled bool)

Disable disable the secure handler or not

func (*HTTPSRedirector) Handle added in v1.0.14

func (sh *HTTPSRedirector) Handle(c *xin.Context)

Handle process xin request

type Localizer

type Localizer struct {
	Locales []string

	LocaleParamNames  []string
	LocaleCookieNames []string
	LocaleHeaderNames []string
}

Localizer localizer middleware

Example
router := xin.Default()

router.Use(NewLocalizer("en", "ja", "zh").Handle)
router.GET("/", func(c *xin.Context) {
	c.String(200, c.Locale)
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/", nil)
req.Header.Add("Accept-Languages", "ja;zh")

client := &http.Client{Timeout: time.Second * 1}
res, _ := client.Do(req)

raw, _ := io.ReadAll(res.Body)
fmt.Println(string(raw))

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func NewLocalizer

func NewLocalizer(locales ...string) *Localizer

NewLocalizer create a default Localizer

func (*Localizer) Handle added in v1.0.10

func (ll *Localizer) Handle(c *xin.Context)

Handle process xin request

type OriginAccessController added in v1.0.12

type OriginAccessController struct {
	AllowOrigins     *hashset.HashSet[string]
	AllowCredentials bool
	AllowMethods     string
	AllowHeaders     string
	ExposeHeaders    string
	MaxAge           int
}

OriginAccessController Access-Control-Allow-Origin response header middleware see - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age if Origins contains the request header 'origin', set the Access-Control-Allow-Origin response header. if the request method is OPTIONS, also set the status code to 200.

func NewOriginAccessController added in v1.0.12

func NewOriginAccessController(origins ...string) *OriginAccessController

NewOriginAccessController create a default OriginAccessController

func (*OriginAccessController) Handle added in v1.0.12

func (ll *OriginAccessController) Handle(c *xin.Context)

Handle process xin request

func (*OriginAccessController) SetAllowCredentials added in v1.0.15

func (ll *OriginAccessController) SetAllowCredentials(allow bool)

SetAllowCredentials set allow Credentials

func (*OriginAccessController) SetAllowHeaders added in v1.0.15

func (ll *OriginAccessController) SetAllowHeaders(headers string)

SetAllowHeaders set allow headers

func (*OriginAccessController) SetAllowMethods added in v1.0.15

func (ll *OriginAccessController) SetAllowMethods(methods string)

SetAllowMethods set Access-Control-Allow-Methods

func (*OriginAccessController) SetAllowOrigins added in v1.0.15

func (ll *OriginAccessController) SetAllowOrigins(origins ...string)

SetAllowOrigins set allow origins

func (*OriginAccessController) SetExposeHeaders added in v1.0.15

func (ll *OriginAccessController) SetExposeHeaders(headers string)

SetExposeHeaders set expose headers

func (*OriginAccessController) SetMaxAge added in v1.0.15

func (ll *OriginAccessController) SetMaxAge(sec int)

SetMaxAge set Access-Control-Max-Age

type ProxiedFlag

type ProxiedFlag int

ProxiedFlag Proxied flag

const (
	ProxiedAny ProxiedFlag = 1 << iota
	ProxiedAuth
	ProxiedExpired
	ProxiedNoCache
	ProxiedNoStore
	ProxiedPrivate
	ProxiedNoLastModified
	ProxiedNoETag
	ProxiedOff = 0
)

Proxied option flags

func (ProxiedFlag) String

func (pf ProxiedFlag) String() string

String return level string

type RequestRateLimiter added in v1.0.27

type RequestRateLimiter struct {
	Limit           int
	Duration        time.Duration
	TrustedClients  []*net.IPNet
	TooManyRequests func(c *xin.Context)
	// contains filtered or unexported fields
}

RequestRateLimiter http request limit middleware

func NewRequestRateLimiter added in v1.0.27

func NewRequestRateLimiter(limit int, duration, cleanupInterval time.Duration) *RequestRateLimiter

NewRequestRateLimiter create a default RequestRateLimiter middleware

func (*RequestRateLimiter) Handle added in v1.0.27

func (rrl *RequestRateLimiter) Handle(c *xin.Context)

Handle process xin request

func (*RequestRateLimiter) SetTrustedClients added in v1.0.27

func (rrl *RequestRateLimiter) SetTrustedClients(cidrs []string) error

type RequestSizeLimiter added in v1.0.27

type RequestSizeLimiter struct {
	MaxBodySize  int64
	DrainBody    bool // drain request body if we are under apache, otherwise the apache will return 502 Bad Gateway
	BodyTooLarge func(c *xin.Context)
}

RequestSizeLimiter http request limit middleware

func NewRequestSizeLimiter added in v1.0.27

func NewRequestSizeLimiter(maxBodySize int64) *RequestSizeLimiter

NewRequestSizeLimiter create a default RequestSizeLimiter middleware

func (*RequestSizeLimiter) Handle added in v1.0.27

func (rsl *RequestSizeLimiter) Handle(c *xin.Context)

Handle process xin request

type ResponseCompressor added in v1.0.22

type ResponseCompressor struct {
	Encodings map[string]CompressorProvider
	// contains filtered or unexported fields
}

ResponseCompressor Compresses responses using the “gzip” method

Example
router := xin.Default()

router.Use(DefaultResponseCompressor().Handle)
router.GET("/", func(c *xin.Context) {
	c.String(200, strings.Repeat("This is a Test!\n", 1000))
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultResponseCompressor added in v1.0.22

func DefaultResponseCompressor() *ResponseCompressor

DefaultResponseCompressor create a default zipper = NewResponseCompressor(1024)

func NewResponseCompressor added in v1.0.22

func NewResponseCompressor(minLength int) *ResponseCompressor

NewResponseCompressor create a http response compressor proxied: ProxiedAny vary: true minLength: 1024

func (*ResponseCompressor) Disable added in v1.0.22

func (xrc *ResponseCompressor) Disable(disabled bool)

Disable disable the gzip compress or not

func (*ResponseCompressor) Handle added in v1.0.22

func (xrc *ResponseCompressor) Handle(ctx *xin.Context)

Handle process xin request

func (*ResponseCompressor) IgnorePathPrefix added in v1.0.22

func (xrc *ResponseCompressor) IgnorePathPrefix(ps ...string)

IgnorePathPrefix ignore URL path prefix

func (*ResponseCompressor) IgnorePathRegexp added in v1.0.22

func (xrc *ResponseCompressor) IgnorePathRegexp(ps ...string)

IgnorePathRegexp ignore URL path regexp

func (*ResponseCompressor) SetHTTPVersion added in v1.0.22

func (xrc *ResponseCompressor) SetHTTPVersion(major, minor int)

SetHTTPVersion Sets the minimum HTTP Proto version of a request required to compress a response.

func (*ResponseCompressor) SetMimeTypes added in v1.0.22

func (xrc *ResponseCompressor) SetMimeTypes(mts ...string)

SetMimeTypes Enables compressing of responses for the specified MIME types. The special value "*" matches any MIME type. Default:

text/html
text/plain
text/xml
text/css
text/javascript
text/json
text/comma-separated-values
text/tab-separated-values
application/xml
application/xhtml+xml
application/rss+xml
application/atom_xml
application/json
application/javascript
application/x-javascript

func (*ResponseCompressor) SetProxied added in v1.0.22

func (xrc *ResponseCompressor) SetProxied(ps ...string)

SetProxied Enables or disables compressing of responses for proxied requests depending on the request and response. The fact that the request is proxied is determined by the presence of the “Via” request header field. The directive accepts multiple parameters: off

disables compression for all proxied requests, ignoring other parameters;

any (Default)

enables compression for all proxied requests.

auth

enables compression if a request header includes the “Authorization” field;

expired

enables compression if a response header includes the “Expires” field with a value that disables caching;

no-cache

enables compression if a response header includes the “Cache-Control” field with the “no-cache” parameter;

no-store

enables compression if a response header includes the “Cache-Control” field with the “no-store” parameter;

private

enables compression if a response header includes the “Cache-Control” field with the “private” parameter;

no_last_modified

enables compression if a response header does not include the “Last-Modified” field;

no_etag

enables compression if a response header does not include the “ETag” field;

func (*ResponseCompressor) Vary added in v1.0.22

func (xrc *ResponseCompressor) Vary(vary bool)

Vary Enables or disables inserting the “Vary: Accept-Encoding” response header field. Default: true

type ResponseHeader

type ResponseHeader struct {
	Header map[string]string
}

ResponseHeader response header middleware

func NewResponseHeader

func NewResponseHeader(header map[string]string) *ResponseHeader

NewResponseHeader create a default ResponseHeader

func (*ResponseHeader) Handle added in v1.0.10

func (rh *ResponseHeader) Handle(c *xin.Context)

Handle process xin request

type TokenProtector

type TokenProtector struct {
	Cryptor        cpt.Cryptor // cryptor to encode/decode cookie, MUST concurrent safe
	Expires        time.Duration
	AttrKey        string
	ParamName      string
	HeaderName     string
	CookieName     string
	CookieMaxAge   time.Duration
	CookieDomain   string
	CookiePath     string
	CookieSecure   bool
	CookieHttpOnly bool
	CookieSameSite http.SameSite
	AbortStatus    int
	AbortFunc      func(*xin.Context)
	// contains filtered or unexported fields
}

TokenProtector token protector for CSRF

func NewTokenProtector

func NewTokenProtector(secret string) *TokenProtector

NewTokenProtector create a default TokenProtector default methods: DELETE, PATCH, POST, PUT

func (*TokenProtector) Handle added in v1.0.10

func (tp *TokenProtector) Handle(c *xin.Context)

Handle process xin request

func (*TokenProtector) RefreshToken

func (tp *TokenProtector) RefreshToken(c *xin.Context) string

func (*TokenProtector) SetMethods

func (tp *TokenProtector) SetMethods(ms ...string)

SetMethods Set the http methods to protect default methods: DELETE, PATCH, POST, PUT

func (*TokenProtector) SetSecret added in v1.0.12

func (tp *TokenProtector) SetSecret(secret string)

SetSecret Set the Cryptor secret

type ZlibCompressorProvider added in v1.0.27

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

func NewZlibCompressorProvider added in v1.0.27

func NewZlibCompressorProvider() *ZlibCompressorProvider

func (*ZlibCompressorProvider) GetCompressor added in v1.0.27

func (gcws *ZlibCompressorProvider) GetCompressor() Compressor

func (*ZlibCompressorProvider) NewCompressor added in v1.0.27

func (gcws *ZlibCompressorProvider) NewCompressor() any

func (*ZlibCompressorProvider) PutCompressor added in v1.0.27

func (gcws *ZlibCompressorProvider) PutCompressor(cw Compressor)

Jump to

Keyboard shortcuts

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