Documentation ¶
Index ¶
- Variables
- func ApplyRequests(ctx *context.LuxContext, middlewares []Set) string
- func ApplyResponses(ctx *context.LuxContext, middlewares []Set) string
- type Set
- func AllowDynamicIPs(checker func(remoteIP string) bool) Set
- func AllowDynamicPorts(checker func(remotePort string) bool) Set
- func AllowStaticIPs(ips ...string) Set
- func AllowStaticPorts(ports ...string) Set
- func Auth(tokenChecker func(authorizaionHeader string, tokenCookie *http.Cookie) bool) Set
- func BlockDynamicIPs(checker func(remoteIP string) bool) Set
- func BlockDynamicPorts(checker func(remotePort string) bool) Set
- func BlockStaticIPs(ips ...string) Set
- func BlockStaticPorts(ports ...string) Set
- func SetAllowHeaders(headers ...string) Set
- func SetAllowMethods(methods ...string) Set
- func SetAllowOrigins(origins ...string) Set
Constants ¶
This section is empty.
Variables ¶
View Source
var CompressBrotli = Set{ Request: nil, Response: func(l *context.LuxContext) (*context.LuxContext, error) { acceptEncodings := strings.Split(l.Request.Header.Get("Accept-Encoding"), ", ") if len(acceptEncodings) > 0 && acceptEncodings[0] != "br" || len(acceptEncodings) == 0 { return l, nil } buf := bytes.NewBuffer(nil) writer := brotli.NewWriter(buf) _, err := writer.Write(l.Response.Body) if err != nil { l.Response.StatusCode = http.StatusInternalServerError return l, err } writer.Flush() writer.Close() l.Response.Body = buf.Bytes() l.Response.Headers.Add("Content-Encoding", "br") l.Request.Header.Set("Accept-Encoding", strings.Join(acceptEncodings[1:], ", ")) return l, nil }, }
View Source
var CompressGzip = Set{ Request: nil, Response: func(l *context.LuxContext) (*context.LuxContext, error) { acceptEncodings := strings.Split(l.Request.Header.Get("Accept-Encoding"), ", ") if len(acceptEncodings) > 0 && acceptEncodings[0] != "gzip" || len(acceptEncodings) == 0 { return l, nil } buf := bytes.NewBuffer(nil) writer := gzip.NewWriter(buf) _, err := writer.Write(l.Response.Body) if err != nil { l.Response.StatusCode = http.StatusInternalServerError return l, err } writer.Flush() writer.Close() l.Response.Body = buf.Bytes() l.Response.Headers.Add("Content-Encoding", "gzip") if len(acceptEncodings) >= 2 && acceptEncodings[1] == "defalte" { acceptEncodings = acceptEncodings[1:] } l.Request.Header.Set("Accept-Encoding", strings.Join(acceptEncodings[1:], ", ")) return l, nil }, }
View Source
var CompressSnappy = Set{ Request: nil, Response: func(l *context.LuxContext) (*context.LuxContext, error) { acceptEncodings := strings.Split(l.Request.Header.Get("Accept-Encoding"), ", ") if len(acceptEncodings) > 0 && acceptEncodings[0] != "snappy" || len(acceptEncodings) == 0 { return l, nil } buf := bytes.NewBuffer(nil) writer := snappy.NewBufferedWriter(buf) _, err := writer.Write(l.Response.Body) if err != nil { return l, err } writer.Flush() writer.Close() l.Response.Body = buf.Bytes() l.Response.Headers.Add("Content-Encoding", "snappy") l.Request.Header.Set("Accept-Encoding", strings.Join(acceptEncodings[1:], ", ")) return l, nil }, }
View Source
var SetAllowCORS = Set{ Request: nil, Response: func(l *context.LuxContext) (*context.LuxContext, error) { l.Response.Headers.Set("Access-Control-Allow-Headers", "*") l.Response.Headers.Set("Access-Control-Allow-Origin", "*") l.Response.Headers.Set("Access-Control-Allow-Methods", "*") l.Response.Headers.Set("Access-Control-Allow-Credentials", "true") return l, nil }, }
View Source
var SetAllowCredentials = Set{ Request: nil, Response: func(l *context.LuxContext) (*context.LuxContext, error) { l.Response.Headers.Set("Access-Control-Allow-Credentials", "true") return l, nil }, }
Functions ¶
func ApplyRequests ¶
func ApplyRequests(ctx *context.LuxContext, middlewares []Set) string
func ApplyResponses ¶
func ApplyResponses(ctx *context.LuxContext, middlewares []Set) string
Types ¶
type Set ¶
type Set struct { Request func(*http.Request) (*http.Request, int) Response func(*context.LuxContext) (*context.LuxContext, error) }
func AllowDynamicIPs ¶
func AllowDynamicPorts ¶
func AllowStaticIPs ¶
func AllowStaticPorts ¶
func BlockDynamicIPs ¶
func BlockDynamicPorts ¶
func BlockStaticIPs ¶
func BlockStaticPorts ¶
func SetAllowHeaders ¶
func SetAllowMethods ¶
func SetAllowOrigins ¶
Click to show internal directories.
Click to hide internal directories.