Documentation ¶
Index ¶
- Constants
- func ContextRequestBodyBuffer(ctx context.Context) (body *bytes.Buffer, ok bool)
- func ContextWithRequestBodyBuffer(parent context.Context, body *bytes.Buffer) context.Context
- func ContextWithXRealIP(parent context.Context, xRealIP string) context.Context
- func ContextXRealIP(ctx context.Context) (xRealIP string)
- func DefaultSetRealIPFrom() []*net.IPNet
- func DoRequest(ctx context.Context, client *http.Client, method, url string, ...) (*http.Response, error)
- func ListenAndServe(server *http.Server) error
- func NewBufferFromResponseBody(response *http.Response) (body *bytes.Buffer, err error)
- func NewCORSHandler(configs ...*CORSConfig) func(next http.Handler) http.Handler
- func NewRequest(ctx context.Context, method, url string, header http.Header, body io.Reader) (*http.Request, error)
- func NewXRealIPHandler(set_real_ip_from []*net.IPNet, real_ip_header string, real_ip_recursive bool, ...) func(next http.Handler) http.Handler
- func ParseCookies(rawCookies string) []*http.Cookie
- func RemoteIP(r *http.Request) string
- func RequestBodyBuffer(r *http.Request) (*bytes.Buffer, error)
- func XRealIP(r *http.Request, set_real_ip_from []*net.IPNet, real_ip_header string, ...) string
- type CORS
- type CORSConfig
- type Cookies
- type HeaderBuilder
- type Middleware
- type NewXRealIPHandlerOption
- type RequestBodyBufferHandler
- type RequestBodyBufferHandlerOption
- type ResponseWriterBuffer
- type ResponseWriterBufferHandler
- type ResponseWriterBufferHandlerOption
- type RoundTripFunc
Constants ¶
View Source
const ( HeaderOrigin = "Origin" HeaderVary = "Vary" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowPrivateNetwork = "Access-Control-Allow-Private-Network" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestPrivateNetwork = "Access-Control-Request-Private-Network" )
View Source
const ( HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" )
View Source
const DefaultRequestBodyBufferingSkipLimit = 1 << 20 // 1 MiB
View Source
const (
HeaderCookie = "Cookie"
)
Variables ¶
This section is empty.
Functions ¶
func ContextWithXRealIP ¶
func ContextXRealIP ¶
func DefaultSetRealIPFrom ¶ added in v0.0.54
func ListenAndServe ¶
func NewCORSHandler ¶
func NewCORSHandler(configs ...*CORSConfig) func(next http.Handler) http.Handler
func NewRequest ¶
func NewXRealIPHandler ¶
func NewXRealIPHandler(set_real_ip_from []*net.IPNet, real_ip_header string, real_ip_recursive bool, opts ...NewXRealIPHandlerOption) func(next http.Handler) http.Handler
NewXRealIPHandler returns realip handler that appends X-Real-IP header. If set_real_ip_from is X-Forwarded-For and it has below values:
X-Forwarded-For: <SpoofingIP>, <ClientIP>, <ProxyIP>, <Proxy2IP>
realip handler set <ClientIP> to X-Real-IP header.
NOTE: Argument naming conforms to NGINX configuration naming.
Example:
httpz.NewXRealIPHandler( httpz.DefaultSetRealIPFrom(), httpz.HeaderXForwardedFor, true, )
func ParseCookies ¶
func XRealIP ¶
func XRealIP(r *http.Request, set_real_ip_from []*net.IPNet, real_ip_header string, real_ip_recursive bool) string
XRealIP returns X-Real-IP value from real_ip_header. If real_ip_header is X-Forwarded-For and it has below values:
X-Forwarded-For: <SpoofingIP>, <ClientIP>, <ProxyIP>, <Proxy2IP>
XRealIP returns <ClientIP>.
NOTE: Argument naming conforms to NGINX configuration naming.
Example:
realip := httpz.XRealIP( r, httpz.DefaultSetRealIPFrom(), httpz.HeaderXForwardedFor, true, )
Types ¶
type CORSConfig ¶
type HeaderBuilder ¶
type HeaderBuilder interface { Add(key, value string) HeaderBuilder Set(key, value string) HeaderBuilder Merge(header http.Header) HeaderBuilder Build() http.Header }
func NewHeaderBuilder ¶
func NewHeaderBuilder() HeaderBuilder
type Middleware ¶
func Middlewares ¶
func Middlewares(middlewares ...func(next http.Handler) http.Handler) Middleware
func (Middleware) Middlewares ¶
func (m Middleware) Middlewares(middlewares ...func(next http.Handler) http.Handler) Middleware
type NewXRealIPHandlerOption ¶ added in v0.0.57
type NewXRealIPHandlerOption interface {
// contains filtered or unexported methods
}
func WithNewXRealIPHandlerOptionClientIPAddressHeader ¶ added in v0.0.57
func WithNewXRealIPHandlerOptionClientIPAddressHeader(header string) NewXRealIPHandlerOption
type RequestBodyBufferHandler ¶
type RequestBodyBufferHandler struct {
// contains filtered or unexported fields
}
func NewRequestBodyBufferHandler ¶
func NewRequestBodyBufferHandler(errorHandler func(rw http.ResponseWriter, r *http.Request, err error), opts ...RequestBodyBufferHandlerOption) *RequestBodyBufferHandler
func (*RequestBodyBufferHandler) Middleware ¶
func (h *RequestBodyBufferHandler) Middleware(next http.Handler) http.Handler
type RequestBodyBufferHandlerOption ¶
type RequestBodyBufferHandlerOption func(h *RequestBodyBufferHandler)
func WithRequestBodyBufferingSkipLimit ¶
func WithRequestBodyBufferingSkipLimit(bufferingSkipLimit int64) RequestBodyBufferHandlerOption
type ResponseWriterBuffer ¶
type ResponseWriterBuffer struct { http.ResponseWriter Buffer *bytes.Buffer // contains filtered or unexported fields }
func (*ResponseWriterBuffer) StatusCode ¶
func (rwb *ResponseWriterBuffer) StatusCode() int
func (*ResponseWriterBuffer) WriteHeader ¶
func (rwb *ResponseWriterBuffer) WriteHeader(statusCode int)
type ResponseWriterBufferHandler ¶
type ResponseWriterBufferHandler struct {
// contains filtered or unexported fields
}
func NewResponseWriterBufferHandler ¶
func NewResponseWriterBufferHandler(responseWriterBufferHandler func(rwb *ResponseWriterBuffer, r *http.Request), opts ...ResponseWriterBufferHandlerOption) *ResponseWriterBufferHandler
func (*ResponseWriterBufferHandler) Middleware ¶
func (h *ResponseWriterBufferHandler) Middleware(next http.Handler) http.Handler
type ResponseWriterBufferHandlerOption ¶
type ResponseWriterBufferHandlerOption func(h *ResponseWriterBufferHandler)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.