Documentation
¶
Index ¶
- Constants
- Variables
- func AppendDeflateBytes(dst, src []byte) []byte
- func AppendDeflateBytesLevel(dst, src []byte, level int) []byte
- func AppendGunzipBytes(dst, src []byte) ([]byte, error)
- func AppendGzipBytes(dst, src []byte) []byte
- func AppendGzipBytesLevel(dst, src []byte, level int) []byte
- func AppendHTMLEscape(dst []byte, s string) []byte
- func AppendHTMLEscapeBytes(dst, s []byte) []byte
- func AppendHTTPDate(dst []byte, date time.Time) []byte
- func AppendIPv4(dst []byte, ip net.IP) []byte
- func AppendInflateBytes(dst, src []byte) ([]byte, error)
- func AppendNormalizedHeaderKey(dst []byte, key string) []byte
- func AppendNormalizedHeaderKeyBytes(dst, key []byte) []byte
- func AppendQuotedArg(dst, src []byte) []byte
- func AppendUint(dst []byte, n int) []byte
- func AppendUnquotedArg(dst, src []byte) []byte
- func AppendUnzstdBytes(dst, src []byte) ([]byte, error)
- func AppendZstdBytes(dst, src []byte) []byte
- func AppendZstdBytesLevel(dst, src []byte, level int) []byte
- func NewFunc(f func(ctx any)) func(ctx any) bool
- func NewStreamReader(sw StreamWriter) io.ReadCloser
- func ParseHTTPDate(date []byte) (time.Time, error)
- func ParseIPv4(dst net.IP, ipStr []byte) (net.IP, error)
- func ParseUfloat(buf []byte) (float64, error)
- func ParseUint(buf []byte) (int, error)
- func ReleaseArgs(a *Args)
- func ReleaseCookie(c *Cookie)
- func ReleaseRequest(req *Request)
- func ReleaseRequestParser(p *Parser)
- func ReleaseResponse(resp *Response)
- func ReleaseResponseParser(p *Parser)
- func ReleaseURI(u *URI)
- func StatusMessage(statusCode int) string
- func VisitHeaderParams(b []byte, f func(key, value []byte) bool)
- func WriteDeflate(w io.Writer, p []byte) (int, error)
- func WriteDeflateLevel(w io.Writer, p []byte, level int) (int, error)
- func WriteGunzip(w io.Writer, p []byte) (int, error)
- func WriteGzip(w io.Writer, p []byte) (int, error)
- func WriteGzipLevel(w io.Writer, p []byte, level int) (int, error)
- func WriteInflate(w io.Writer, p []byte) (int, error)
- func WriteUnzstd(w io.Writer, p []byte) (int, error)
- func WriteZstdLevel(w io.Writer, p []byte, level int) (int, error)
- type Args
- func (a *Args) Add(key, value string)
- func (a *Args) AddBytesK(key []byte, value string)
- func (a *Args) AddBytesKNoValue(key []byte)
- func (a *Args) AddBytesKV(key, value []byte)
- func (a *Args) AddBytesV(key string, value []byte)
- func (a *Args) AddNoValue(key string)
- func (a *Args) All() iter.Seq2[[]byte, []byte]
- func (a *Args) AppendBytes(dst []byte) []byte
- func (a *Args) CopyTo(dst *Args)
- func (a *Args) Del(key string)
- func (a *Args) DelBytes(key []byte)
- func (a *Args) GetBool(key string) bool
- func (a *Args) GetUfloat(key string) (float64, error)
- func (a *Args) GetUfloatOrZero(key string) float64
- func (a *Args) GetUint(key string) (int, error)
- func (a *Args) GetUintOrZero(key string) int
- func (a *Args) Has(key string) bool
- func (a *Args) HasBytes(key []byte) bool
- func (a *Args) Len() int
- func (a *Args) Parse(s string)
- func (a *Args) ParseBytes(b []byte)
- func (a *Args) Peek(key string) []byte
- func (a *Args) PeekBytes(key []byte) []byte
- func (a *Args) PeekMulti(key string) [][]byte
- func (a *Args) PeekMultiBytes(key []byte) [][]byte
- func (a *Args) QueryString() []byte
- func (a *Args) Reset()
- func (a *Args) Set(key, value string)
- func (a *Args) SetBytesK(key []byte, value string)
- func (a *Args) SetBytesKNoValue(key []byte)
- func (a *Args) SetBytesKV(key, value []byte)
- func (a *Args) SetBytesV(key string, value []byte)
- func (a *Args) SetNoValue(key string)
- func (a *Args) SetUint(key string, value int)
- func (a *Args) SetUintBytes(key []byte, value int)
- func (a *Args) Sort(f func(x, y []byte) int)
- func (a *Args) String() string
- func (a *Args) VisitAll(f func(key, value []byte))deprecated
- func (a *Args) WriteTo(w io.Writer) (int64, error)
- type Context
- func (c *Context) Abort()
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) HTML(statusCode int, html string)
- func (c *Context) JSON(statusCode int, data any)
- func (c *Context) Next()
- func (c *Context) NotFound()
- func (c *Context) Param(key string) string
- func (c *Context) PostForm(key string) string
- func (c *Context) Query(key string) string
- func (c *Context) Redirect(statusCode int, location string)
- func (c *Context) Set(key string, value any)
- func (c *Context) String(statusCode int, format string, values ...any)
- type Cookie
- func (c *Cookie) AppendBytes(dst []byte) []byte
- func (c *Cookie) Cookie() []byte
- func (c *Cookie) CopyTo(src *Cookie)
- func (c *Cookie) Domain() []byte
- func (c *Cookie) Expire() time.Time
- func (c *Cookie) HTTPOnly() bool
- func (c *Cookie) Key() []byte
- func (c *Cookie) MaxAge() int
- func (c *Cookie) Parse(src string) error
- func (c *Cookie) ParseBytes(src []byte) error
- func (c *Cookie) Partitioned() bool
- func (c *Cookie) Path() []byte
- func (c *Cookie) Reset()
- func (c *Cookie) SameSite() CookieSameSite
- func (c *Cookie) Secure() bool
- func (c *Cookie) SetDomain(domain string)
- func (c *Cookie) SetDomainBytes(domain []byte)
- func (c *Cookie) SetExpire(expire time.Time)
- func (c *Cookie) SetHTTPOnly(httpOnly bool)
- func (c *Cookie) SetKey(key string)
- func (c *Cookie) SetKeyBytes(key []byte)
- func (c *Cookie) SetMaxAge(seconds int)
- func (c *Cookie) SetPartitioned(partitioned bool)
- func (c *Cookie) SetPath(path string)
- func (c *Cookie) SetPathBytes(path []byte)
- func (c *Cookie) SetSameSite(mode CookieSameSite)
- func (c *Cookie) SetSecure(secure bool)
- func (c *Cookie) SetValue(value string)
- func (c *Cookie) SetValueBytes(value []byte)
- func (c *Cookie) String() string
- func (c *Cookie) Value() []byte
- func (c *Cookie) WriteTo(w io.Writer) (int64, error)
- type CookieSameSite
- type ErrNothingRead
- type ErrSmallBuffer
- type EscapeError
- type HandlerFunc
- type InvalidHostError
- type MiddlewareFunc
- type NewWriterFunc
- type Param
- type Params
- type ParseState
- type Parser
- type Request
- func (req *Request) AppendBodyRaw(body []byte)
- func (req *Request) Body() []byte
- func (req *Request) BodyStream() io.Reader
- func (req *Request) BodyString() string
- func (req *Request) BodyWriter() io.Writer
- func (req *Request) CloseBodyStream() error
- func (req *Request) Host() []byte
- func (req *Request) HostString() string
- func (req *Request) IsBodyStream() bool
- func (req *Request) Method() []byte
- func (req *Request) MethodString() string
- func (req *Request) PostArgs() *Args
- func (req *Request) QueryArgs() *Args
- func (req *Request) RequestURI() []byte
- func (req *Request) Reset()
- func (req *Request) ResetBody()
- func (req *Request) SetBody(body string)
- func (req *Request) SetBodyRaw(body []byte)
- func (req *Request) SetBodyStream(bodyStream io.Reader, bodySize int)
- func (req *Request) SetBodyStreamWriter(sw StreamWriter)
- func (req *Request) SetHost(host string)
- func (req *Request) SetMethod(method string)
- func (req *Request) SetRequestURI(requestURI string)
- func (req *Request) SetURI(uri *URI)
- func (req *Request) String() string
- func (req *Request) URI() *URI
- func (req *Request) Write(w *bufio.Writer) error
- func (req *Request) WriteDeflate(p []byte) (int, error)
- func (req *Request) WriteDeflateLevel(p []byte, level int) (int, error)
- func (req *Request) WriteGzip(p []byte) (int, error)
- func (req *Request) WriteGzipLevel(p []byte, level int) (int, error)
- func (req *Request) WriteZstd(p []byte) (int, error)
- func (req *Request) WriteZstdLevel(p []byte, level int) (int, error)
- type RequestHeader
- func (h *RequestHeader) Add(key, value string)
- func (h *RequestHeader) AddBytesK(key []byte, value string)
- func (h *RequestHeader) AddBytesKV(key, value []byte)
- func (h *RequestHeader) AddBytesV(key string, value []byte)
- func (h *RequestHeader) AddTrailer(trailer string) error
- func (h *RequestHeader) AddTrailerBytes(trailer []byte) (err error)
- func (h *RequestHeader) All() iter.Seq2[[]byte, []byte]
- func (h *RequestHeader) AllInOrder() iter.Seq2[[]byte, []byte]
- func (h *RequestHeader) AppendBytes(dst []byte) []byte
- func (h *RequestHeader) ConnectionClose() bool
- func (h *RequestHeader) ConnectionUpgrade() bool
- func (h *RequestHeader) ContentEncoding() []byte
- func (h *RequestHeader) ContentLength() int
- func (h *RequestHeader) ContentType() []byte
- func (h *RequestHeader) Cookie(key string) []byte
- func (h *RequestHeader) CookieBytes(key []byte) []byte
- func (h *RequestHeader) Cookies() iter.Seq2[[]byte, []byte]
- func (h *RequestHeader) CopyTo(dst *RequestHeader)
- func (h *RequestHeader) Del(key string)
- func (h *RequestHeader) DelAllCookies()
- func (h *RequestHeader) DelBytes(key []byte)
- func (h *RequestHeader) DelCookie(key string)
- func (h *RequestHeader) DelCookieBytes(key []byte)
- func (h *RequestHeader) DisableNormalizing()
- func (h *RequestHeader) DisableSpecialHeader()
- func (h *RequestHeader) EnableNormalizing()
- func (h *RequestHeader) EnableSpecialHeader()
- func (h *RequestHeader) Get(key string) string
- func (h *RequestHeader) HasAcceptEncoding(acceptEncoding string) bool
- func (h *RequestHeader) HasAcceptEncodingBytes(acceptEncoding []byte) bool
- func (h *RequestHeader) Header() []byte
- func (h *RequestHeader) Host() []byte
- func (h *RequestHeader) IsConnect() bool
- func (h *RequestHeader) IsDelete() bool
- func (h *RequestHeader) IsGet() bool
- func (h *RequestHeader) IsHTTP11() bool
- func (h *RequestHeader) IsHead() bool
- func (h *RequestHeader) IsOptions() bool
- func (h *RequestHeader) IsPatch() bool
- func (h *RequestHeader) IsPost() bool
- func (h *RequestHeader) IsPut() bool
- func (h *RequestHeader) IsTrace() bool
- func (h *RequestHeader) Len() int
- func (h *RequestHeader) Method() []byte
- func (h *RequestHeader) MultipartFormBoundary() []byte
- func (h *RequestHeader) Peek(key string) []byte
- func (h *RequestHeader) PeekAll(key string) [][]byte
- func (h *RequestHeader) PeekBytes(key []byte) []byte
- func (h *RequestHeader) PeekKeys() [][]byte
- func (h *RequestHeader) PeekTrailerKeys() [][]byte
- func (h *RequestHeader) Protocol() []byte
- func (h *RequestHeader) RawHeaders() []byte
- func (h *RequestHeader) Read(r *bufio.Reader) error
- func (h *RequestHeader) ReadTrailer(r *bufio.Reader) error
- func (h *RequestHeader) Referer() []byte
- func (h *RequestHeader) RequestURI() []byte
- func (h *RequestHeader) Reset()
- func (h *RequestHeader) ResetConnectionClose()
- func (h *RequestHeader) Set(key, value string)
- func (h *RequestHeader) SetByteRange(startPos, endPos int)
- func (h *RequestHeader) SetBytesK(key []byte, value string)
- func (h *RequestHeader) SetBytesKV(key, value []byte)
- func (h *RequestHeader) SetBytesV(key string, value []byte)
- func (h *RequestHeader) SetCanonical(key, value []byte)
- func (h *RequestHeader) SetConnectionClose()
- func (h *RequestHeader) SetContentEncoding(contentEncoding string)
- func (h *RequestHeader) SetContentEncodingBytes(contentEncoding []byte)
- func (h *RequestHeader) SetContentLength(contentLength int)
- func (h *RequestHeader) SetContentType(contentType string)
- func (h *RequestHeader) SetContentTypeBytes(contentType []byte)
- func (h *RequestHeader) SetCookie(key, value string)
- func (h *RequestHeader) SetCookieBytesK(key []byte, value string)
- func (h *RequestHeader) SetCookieBytesKV(key, value []byte)
- func (h *RequestHeader) SetHost(host string)
- func (h *RequestHeader) SetHostBytes(host []byte)
- func (h *RequestHeader) SetMethod(method string)
- func (h *RequestHeader) SetMethodBytes(method []byte)
- func (h *RequestHeader) SetMultipartFormBoundary(boundary string)
- func (h *RequestHeader) SetMultipartFormBoundaryBytes(boundary []byte)
- func (h *RequestHeader) SetNoDefaultContentType(noDefaultContentType bool)
- func (h *RequestHeader) SetNonSpecial(key, value []byte)
- func (h *RequestHeader) SetProtocol(protocol string)
- func (h *RequestHeader) SetProtocolBytes(protocol []byte)
- func (h *RequestHeader) SetReferer(referer string)
- func (h *RequestHeader) SetRefererBytes(referer []byte)
- func (h *RequestHeader) SetRequestURI(requestURI string)
- func (h *RequestHeader) SetRequestURIBytes(requestURI []byte)
- func (h *RequestHeader) SetTrailer(trailer string) error
- func (h *RequestHeader) SetTrailerBytes(trailer []byte) error
- func (h *RequestHeader) SetUserAgent(userAgent string)
- func (h *RequestHeader) SetUserAgentBytes(userAgent []byte)
- func (h *RequestHeader) String() string
- func (h *RequestHeader) TrailerHeader() []byte
- func (h *RequestHeader) Trailers() iter.Seq[[]byte]
- func (h *RequestHeader) UserAgent() []byte
- func (h *RequestHeader) VisitAll(f func(key, value []byte))deprecated
- func (h *RequestHeader) VisitAllCookie(f func(key, value []byte))deprecated
- func (h *RequestHeader) VisitAllInOrder(f func(key, value []byte))deprecated
- func (h *RequestHeader) VisitAllTrailer(f func(value []byte))deprecated
- func (h *RequestHeader) Write(w *bufio.Writer) error
- func (h *RequestHeader) WriteTo(w io.Writer) (int64, error)
- type Response
- func (resp *Response) AppendBody(p []byte)
- func (resp *Response) AppendBodyRaw(body []byte)
- func (resp *Response) AppendBodyString(s string)
- func (resp *Response) Body() []byte
- func (resp *Response) BodyStream() io.Reader
- func (resp *Response) BodyString() string
- func (resp *Response) BodyWriter() io.Writer
- func (resp *Response) CloseBodyStream() error
- func (resp *Response) ConnectionClose() bool
- func (resp *Response) ContentLength() int
- func (resp *Response) ContentType() []byte
- func (resp *Response) IsBodyStream() bool
- func (resp *Response) Redirect(uri string, statusCode int)
- func (resp *Response) Reset()
- func (resp *Response) ResetBody()
- func (resp *Response) Set(key, value string)
- func (resp *Response) SetBody(body string)
- func (resp *Response) SetBodyRaw(body []byte)
- func (resp *Response) SetBodyStream(bodyStream io.Reader, bodySize int)
- func (resp *Response) SetBodyStreamWriter(sw StreamWriter)
- func (resp *Response) SetConnectionClose()
- func (resp *Response) SetContentLength(contentLength int)
- func (resp *Response) SetContentType(contentType string)
- func (resp *Response) SetHTML(html string)
- func (resp *Response) SetJSON(data any) error
- func (resp *Response) SetStatusCode(statusCode int)
- func (resp *Response) SetText(text string)
- func (resp *Response) StatusCode() int
- func (resp *Response) Write(w metanet.Conn) error
- func (resp *Response) WriteDeflate(p []byte) (int, error)
- func (resp *Response) WriteDeflateLevel(p []byte, level int) (int, error)
- func (resp *Response) WriteGzip(p []byte) (int, error)
- func (resp *Response) WriteGzipLevel(p []byte, level int) (int, error)
- func (resp *Response) WriteZstd(p []byte) (int, error)
- func (resp *Response) WriteZstdLevel(p []byte, level int) (int, error)
- type ResponseHeader
- func (h *ResponseHeader) Add(key, value string)
- func (h *ResponseHeader) AddBytesK(key []byte, value string)
- func (h *ResponseHeader) AddBytesKV(key, value []byte)
- func (h *ResponseHeader) AddBytesV(key string, value []byte)
- func (h *ResponseHeader) AddTrailer(trailer string) error
- func (h *ResponseHeader) AddTrailerBytes(trailer []byte) (err error)
- func (h *ResponseHeader) All() iter.Seq2[[]byte, []byte]
- func (h *ResponseHeader) AppendBytes(dst []byte) []byte
- func (h *ResponseHeader) ConnectionClose() bool
- func (h *ResponseHeader) ConnectionUpgrade() bool
- func (h *ResponseHeader) ContentEncoding() []byte
- func (h *ResponseHeader) ContentLength() int
- func (h *ResponseHeader) ContentType() []byte
- func (h *ResponseHeader) Cookie(cookie *Cookie) bool
- func (h *ResponseHeader) Cookies() iter.Seq2[[]byte, []byte]
- func (h *ResponseHeader) CopyTo(dst *ResponseHeader)
- func (h *ResponseHeader) Del(key string)
- func (h *ResponseHeader) DelAllCookies()
- func (h *ResponseHeader) DelBytes(key []byte)
- func (h *ResponseHeader) DelClientCookie(key string)
- func (h *ResponseHeader) DelClientCookieBytes(key []byte)
- func (h *ResponseHeader) DelCookie(key string)
- func (h *ResponseHeader) DelCookieBytes(key []byte)
- func (h *ResponseHeader) DisableNormalizing()
- func (h *ResponseHeader) EnableNormalizing()
- func (h *ResponseHeader) Header() []byte
- func (h *ResponseHeader) IsHTTP11() bool
- func (h *ResponseHeader) Len() int
- func (h *ResponseHeader) Peek(key string) []byte
- func (h *ResponseHeader) PeekAll(key string) [][]byte
- func (h *ResponseHeader) PeekBytes(key []byte) []byte
- func (h *ResponseHeader) PeekCookie(key string) []byte
- func (h *ResponseHeader) PeekKeys() [][]byte
- func (h *ResponseHeader) PeekTrailerKeys() [][]byte
- func (h *ResponseHeader) Protocol() []byte
- func (h *ResponseHeader) Read(r *bufio.Reader) error
- func (h *ResponseHeader) ReadTrailer(r *bufio.Reader) error
- func (h *ResponseHeader) Reset()
- func (h *ResponseHeader) ResetConnectionClose()
- func (h *ResponseHeader) Server() []byte
- func (h *ResponseHeader) Set(key, value string)
- func (h *ResponseHeader) SetBytesK(key []byte, value string)
- func (h *ResponseHeader) SetBytesKV(key, value []byte)
- func (h *ResponseHeader) SetBytesV(key string, value []byte)
- func (h *ResponseHeader) SetCanonical(key, value []byte)
- func (h *ResponseHeader) SetConnectionClose()
- func (h *ResponseHeader) SetContentEncoding(contentEncoding string)
- func (h *ResponseHeader) SetContentEncodingBytes(contentEncoding []byte)
- func (h *ResponseHeader) SetContentLength(contentLength int)
- func (h *ResponseHeader) SetContentRange(startPos, endPos, contentLength int)
- func (h *ResponseHeader) SetContentType(contentType string)
- func (h *ResponseHeader) SetContentTypeBytes(contentType []byte)
- func (h *ResponseHeader) SetCookie(cookie *Cookie)
- func (h *ResponseHeader) SetLastModified(t time.Time)
- func (h *ResponseHeader) SetNoDefaultContentType(noDefaultContentType bool)
- func (h *ResponseHeader) SetNonSpecial(key, value []byte)
- func (h *ResponseHeader) SetProtocol(protocol []byte)
- func (h *ResponseHeader) SetServer(server string)
- func (h *ResponseHeader) SetServerBytes(server []byte)
- func (h *ResponseHeader) SetStatusCode(statusCode int)
- func (h *ResponseHeader) SetStatusMessage(statusMessage []byte)
- func (h *ResponseHeader) SetTrailer(trailer string) error
- func (h *ResponseHeader) SetTrailerBytes(trailer []byte) error
- func (h *ResponseHeader) StatusCode() int
- func (h *ResponseHeader) StatusMessage() []byte
- func (h *ResponseHeader) String() string
- func (h *ResponseHeader) TrailerHeader() []byte
- func (h *ResponseHeader) Trailers() iter.Seq[[]byte]
- func (h *ResponseHeader) VisitAll(f func(key, value []byte))deprecated
- func (h *ResponseHeader) VisitAllCookie(f func(key, value []byte))deprecated
- func (h *ResponseHeader) VisitAllTrailer(f func(value []byte))deprecated
- func (h *ResponseHeader) Write(w metanet.Conn) error
- func (h *ResponseHeader) WriteTo(w io.Writer) (int64, error)
- type RouteGroup
- func (g *RouteGroup) Any(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) Group(prefix string, middlewares ...MiddlewareFunc) *RouteGroup
- func (g *RouteGroup) HEAD(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) OPTIONS(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) PATCH(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouteGroup) Use(middlewares ...MiddlewareFunc)
- type Router
- func (r *Router) Any(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) Group(prefix string, middlewares ...MiddlewareFunc) *RouteGroup
- func (r *Router) HEAD(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) Handle(ctx *Context)
- func (r *Router) NotFound(handler HandlerFunc)
- func (r *Router) OPTIONS(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) PATCH(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (r *Router) Use(middlewares ...MiddlewareFunc)
- type StreamWriter
- type URI
- func (u *URI) AppendBytes(dst []byte) []byte
- func (u *URI) CopyTo(dst *URI)
- func (u *URI) FullURI() []byte
- func (u *URI) Hash() []byte
- func (u *URI) Host() []byte
- func (u *URI) LastPathSegment() []byte
- func (u *URI) Parse(host, uri []byte) error
- func (u *URI) Password() []byte
- func (u *URI) Path() []byte
- func (u *URI) PathOriginal() []byte
- func (u *URI) QueryArgs() *Args
- func (u *URI) QueryString() []byte
- func (u *URI) RequestURI() []byte
- func (u *URI) Reset()
- func (u *URI) Scheme() []byte
- func (u *URI) SetHash(hash string)
- func (u *URI) SetHashBytes(hash []byte)
- func (u *URI) SetHost(host string)
- func (u *URI) SetHostBytes(host []byte)
- func (u *URI) SetPassword(password string)
- func (u *URI) SetPasswordBytes(password []byte)
- func (u *URI) SetPath(path string)
- func (u *URI) SetPathBytes(path []byte)
- func (u *URI) SetQueryString(queryString string)
- func (u *URI) SetQueryStringBytes(queryString []byte)
- func (u *URI) SetScheme(scheme string)
- func (u *URI) SetSchemeBytes(scheme []byte)
- func (u *URI) SetUsername(username string)
- func (u *URI) SetUsernameBytes(username []byte)
- func (u *URI) String() string
- func (u *URI) Update(newURI string)
- func (u *URI) UpdateBytes(newURI []byte)
- func (u *URI) Username() []byte
- func (u *URI) WriteTo(w io.Writer) (int64, error)
- type Writer
Constants ¶
const ( CompressNoCompression = flate.NoCompression CompressBestSpeed = flate.BestSpeed CompressBestCompression = flate.BestCompression CompressDefaultCompression = 6 // flate.DefaultCompression CompressHuffmanOnly = -2 // flate.HuffmanOnly )
Supported compression levels.
const ( // Authentication. HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" // Caching. HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" // Client hints. HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" // Conditionals. HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" // Connection management. HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" HeaderProxyConnection = "Proxy-Connection" // Content negotiation. HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" // Controls. HeaderCookie = "Cookie" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-Cookie" // CORS. HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderOrigin = "Origin" HeaderTimingAllowOrigin = "Timing-Allow-Origin" HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies" // Do Not Track. HeaderDNT = "DNT" HeaderTk = "Tk" // Downloads. HeaderContentDisposition = "Content-Disposition" // Message body information. HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" // Proxies. HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" // Redirects. HeaderLocation = "Location" // Request context. HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" // Response context. HeaderAllow = "Allow" HeaderServer = "Server" // Range requests. HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" // Security. HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy" HeaderExpectCT = "Expect-CT" HeaderFeaturePolicy = "Feature-Policy" HeaderPublicKeyPins = "Public-Key-Pins" HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXDownloadOptions = "X-Download-Options" HeaderXFrameOptions = "X-Frame-Options" HeaderXPoweredBy = "X-Powered-By" HeaderXXSSProtection = "X-XSS-Protection" // Server-sent event. HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" // Transfer coding. HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" // WebSockets. HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" // #nosec G101 HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" // Other. HeaderAcceptPatch = "Accept-Patch" HeaderAcceptPushPolicy = "Accept-Push-Policy" HeaderAcceptSignature = "Accept-Signature" HeaderAltSvc = "Alt-Svc" HeaderDate = "Date" HeaderIndex = "Index" HeaderLargeAllocation = "Large-Allocation" HeaderLink = "Link" HeaderPushPolicy = "Push-Policy" HeaderRetryAfter = "Retry-After" HeaderServerTiming = "Server-Timing" HeaderSignature = "Signature" HeaderSignedHeaders = "Signed-Headers" HeaderSourceMap = "SourceMap" HeaderUpgrade = "Upgrade" HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control" HeaderXPingback = "X-Pingback" HeaderXRequestedWith = "X-Requested-With" HeaderXRobotsTag = "X-Robots-Tag" HeaderXUACompatible = "X-UA-Compatible" )
Headers.
const ( MethodGet = "GET" // RFC 7231, 4.3.1 MethodHead = "HEAD" // RFC 7231, 4.3.2 MethodPost = "POST" // RFC 7231, 4.3.3 MethodPut = "PUT" // RFC 7231, 4.3.4 MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" // RFC 7231, 4.3.5 MethodConnect = "CONNECT" // RFC 7231, 4.3.6 MethodOptions = "OPTIONS" // RFC 7231, 4.3.7 MethodTrace = "TRACE" // RFC 7231, 4.3.8 )
HTTP methods were copied from net/http.
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 StatusEarlyHints = 103 // RFC 8297 StatusOK = 200 // RFC 7231, 6.3.1 StatusCreated = 201 // RFC 7231, 6.3.2 StatusAccepted = 202 // RFC 7231, 6.3.3 StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4 StatusNoContent = 204 // RFC 7231, 6.3.5 StatusResetContent = 205 // RFC 7231, 6.3.6 StatusPartialContent = 206 // RFC 7233, 4.1 StatusMultiStatus = 207 // RFC 4918, 11.1 StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusMovedPermanently = 301 // RFC 7231, 6.4.2 StatusFound = 302 // RFC 7231, 6.4.3 StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusNotModified = 304 // RFC 7232, 4.1 StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusPermanentRedirect = 308 // RFC 7538, 3 StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusForbidden = 403 // RFC 7231, 6.5.3 StatusNotFound = 404 // RFC 7231, 6.5.4 StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusConflict = 409 // RFC 7231, 6.5.8 StatusGone = 410 // RFC 7231, 6.5.9 StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusTeapot = 418 // RFC 7168, 2.3.3 StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 StatusNotExtended = 510 // RFC 2774, 7 StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 )
HTTP status codes were stolen from net/http.
const ( CompressZstdSpeedNotSet = iota CompressZstdBestSpeed CompressZstdDefault CompressZstdSpeedBetter CompressZstdBestCompression )
Variables ¶
var ( // CookieExpireDelete may be set on Cookie.Expire for expiring the given cookie. CookieExpireDelete = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) // CookieExpireUnlimited indicates that the cookie doesn't expire. CookieExpireUnlimited = zeroTime )
var DeprecatedNewlineIncludeContext atomic.Bool
DeprecatedNewlineIncludeContext is used to control whether the context of the header is included in the warning message about the deprecated newline separator. Warning: this can potentially leak sensitive information such as auth headers.
var ErrBadTrailer = errors.New("contain forbidden trailer")
var ErrNoArgValue = errors.New("no Args value for the given key")
ErrNoArgValue is returned when Args value with the given key is missing.
var ErrTimeout = &timeoutError{}
ErrTimeout is returned from timed out calls.
var ErrorInvalidURI = errors.New("invalid uri")
Functions ¶
func AppendDeflateBytes ¶
AppendDeflateBytes appends deflated src to dst and returns the resulting dst.
func AppendDeflateBytesLevel ¶
AppendDeflateBytesLevel appends deflated src to dst using the given compression level and returns the resulting dst.
Supported compression levels are:
- CompressNoCompression
- CompressBestSpeed
- CompressBestCompression
- CompressDefaultCompression
- CompressHuffmanOnly
func AppendGunzipBytes ¶
AppendGunzipBytes appends gunzipped src to dst and returns the resulting dst.
func AppendGzipBytes ¶
AppendGzipBytes appends gzipped src to dst and returns the resulting dst.
func AppendGzipBytesLevel ¶
AppendGzipBytesLevel appends gzipped src to dst using the given compression level and returns the resulting dst.
Supported compression levels are:
- CompressNoCompression
- CompressBestSpeed
- CompressBestCompression
- CompressDefaultCompression
- CompressHuffmanOnly
func AppendHTMLEscape ¶
AppendHTMLEscape appends html-escaped s to dst and returns the extended dst.
func AppendHTMLEscapeBytes ¶
AppendHTMLEscapeBytes appends html-escaped s to dst and returns the extended dst.
func AppendHTTPDate ¶
AppendHTTPDate appends HTTP-compliant (RFC1123) representation of date to dst and returns the extended dst.
func AppendIPv4 ¶
AppendIPv4 appends string representation of the given ip v4 to dst and returns the extended dst.
func AppendInflateBytes ¶
AppendInflateBytes appends inflated src to dst and returns the resulting dst.
func AppendNormalizedHeaderKey ¶
AppendNormalizedHeaderKey appends normalized header key (name) to dst and returns the resulting dst.
Normalized header key starts with uppercase letter. The first letters after dashes are also uppercased. All the other letters are lowercased. Examples:
- coNTENT-TYPe -> Content-Type
- HOST -> Host
- foo-bar-baz -> Foo-Bar-Baz
func AppendNormalizedHeaderKeyBytes ¶
AppendNormalizedHeaderKeyBytes appends normalized header key (name) to dst and returns the resulting dst.
Normalized header key starts with uppercase letter. The first letters after dashes are also uppercased. All the other letters are lowercased. Examples:
- coNTENT-TYPe -> Content-Type
- HOST -> Host
- foo-bar-baz -> Foo-Bar-Baz
func AppendQuotedArg ¶
AppendQuotedArg appends url-encoded src to dst and returns appended dst.
func AppendUint ¶
AppendUint appends n to dst and returns the extended dst.
func AppendUnquotedArg ¶
AppendUnquotedArg appends url-decoded src to dst and returns appended dst.
dst may point to src. In this case src will be overwritten.
func AppendUnzstdBytes ¶
AppendUnzstdBytes appends unzstd src to dst and returns the resulting dst.
func AppendZstdBytes ¶
AppendZstdBytes appends zstd src to dst and returns the resulting dst.
func AppendZstdBytesLevel ¶
func NewFunc ¶
NewFunc returns stackless wrapper for the function f.
Unlike f, the returned stackless wrapper doesn't use stack space on the goroutine that calls it. The wrapper may save a lot of stack space if the following conditions are met:
- f doesn't contain blocking calls on network, I/O or channels;
- f uses a lot of stack space;
- the wrapper is called from high number of concurrent goroutines.
The stackless wrapper returns false if the call cannot be processed at the moment due to high load.
func NewStreamReader ¶
func NewStreamReader(sw StreamWriter) io.ReadCloser
NewStreamReader returns a reader, which replays all the data generated by sw.
The returned reader may be passed to Response.SetBodyStream.
Close must be called on the returned reader after all the required data has been read. Otherwise goroutine leak may occur.
See also Response.SetBodyStreamWriter.
func ParseHTTPDate ¶
ParseHTTPDate parses HTTP-compliant (RFC1123) date.
func ParseUfloat ¶
ParseUfloat parses unsigned float from buf.
func ReleaseArgs ¶
func ReleaseArgs(a *Args)
ReleaseArgs returns the object acquired via AcquireArgs to the pool.
Do not access the released Args object, otherwise data races may occur.
func ReleaseCookie ¶
func ReleaseCookie(c *Cookie)
ReleaseCookie returns the Cookie object acquired with AcquireCookie back to the pool.
Do not access released Cookie object, otherwise data races may occur.
func ReleaseRequest ¶
func ReleaseRequest(req *Request)
ReleaseRequest returns req acquired via AcquireRequest to request pool.
func ReleaseRequestParser ¶
func ReleaseRequestParser(p *Parser)
ReleaseRequestParser Release request parser
func ReleaseResponse ¶
func ReleaseResponse(resp *Response)
ReleaseResponse returns resp acquired via AcquireResponse to response pool.
func ReleaseResponseParser ¶
func ReleaseResponseParser(p *Parser)
ReleaseResponseParser Release response parser
func ReleaseURI ¶
func ReleaseURI(u *URI)
ReleaseURI releases the URI acquired via AcquireURI.
The released URI mustn't be used after releasing it, otherwise data races may occur.
func StatusMessage ¶
StatusMessage returns HTTP status message for the given status code.
func VisitHeaderParams ¶
VisitHeaderParams calls f for each parameter in the given header bytes. It stops processing when f returns false or an invalid parameter is found. Parameter values may be quoted, in which case \ is treated as an escape character, and the value is unquoted before being passed to value. See: https://www.rfc-editor.org/rfc/rfc9110#section-5.6.6
f must not retain references to key and/or value after returning. Copy key and/or value contents before returning if you need retaining them.
func WriteDeflate ¶
WriteDeflate writes deflated p to w and returns the number of compressed bytes written to w.
func WriteDeflateLevel ¶
WriteDeflateLevel writes deflated p to w using the given compression level and returns the number of compressed bytes written to w.
Supported compression levels are:
- CompressNoCompression
- CompressBestSpeed
- CompressBestCompression
- CompressDefaultCompression
- CompressHuffmanOnly
func WriteGunzip ¶
WriteGunzip writes ungzipped p to w and returns the number of uncompressed bytes written to w.
func WriteGzip ¶
WriteGzip writes gzipped p to w and returns the number of compressed bytes written to w.
func WriteGzipLevel ¶
WriteGzipLevel writes gzipped p to w using the given compression level and returns the number of compressed bytes written to w.
Supported compression levels are:
- CompressNoCompression
- CompressBestSpeed
- CompressBestCompression
- CompressDefaultCompression
- CompressHuffmanOnly
func WriteInflate ¶
WriteInflate writes inflated p to w and returns the number of uncompressed bytes written to w.
func WriteUnzstd ¶
WriteUnzstd writes unzstd p to w and returns the number of uncompressed bytes written to w.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args represents query arguments.
It is forbidden copying Args instances. Create new instances instead and use CopyTo().
Args instance MUST NOT be used from concurrently running goroutines.
func AcquireArgs ¶
func AcquireArgs() *Args
AcquireArgs returns an empty Args object from the pool.
The returned Args may be returned to the pool with ReleaseArgs when no longer needed. This allows reducing GC load.
func (*Args) AddBytesK ¶
AddBytesK adds 'key=value' argument.
Multiple values for the same key may be added.
func (*Args) AddBytesKNoValue ¶
AddBytesKNoValue adds only 'key' as argument without the '='.
Multiple values for the same key may be added.
func (*Args) AddBytesKV ¶
AddBytesKV adds 'key=value' argument.
Multiple values for the same key may be added.
func (*Args) AddBytesV ¶
AddBytesV adds 'key=value' argument.
Multiple values for the same key may be added.
func (*Args) AddNoValue ¶
AddNoValue adds only 'key' as argument without the '='.
Multiple values for the same key may be added.
func (*Args) All ¶
All returns an iterator over key-value pairs from args.
The key and value may invalid outside the iteration loop. Make copies if you need to use them after the loop ends.
func (*Args) AppendBytes ¶
AppendBytes appends query string to dst and returns the extended dst.
func (*Args) GetBool ¶
GetBool returns boolean value for the given key.
true is returned for "1", "t", "T", "true", "TRUE", "True", "y", "yes", "Y", "YES", "Yes", otherwise false is returned.
func (*Args) GetUfloatOrZero ¶
GetUfloatOrZero returns ufloat value for the given key.
Zero (0) is returned on error.
func (*Args) GetUintOrZero ¶
GetUintOrZero returns uint value for the given key.
Zero (0) is returned on error.
func (*Args) ParseBytes ¶
ParseBytes parses the given b containing query args.
func (*Args) Peek ¶
Peek returns query arg value for the given key.
The returned value is valid until the Args is reused or released (ReleaseArgs). Do not store references to the returned value. Make copies instead.
func (*Args) PeekBytes ¶
PeekBytes returns query arg value for the given key.
The returned value is valid until the Args is reused or released (ReleaseArgs). Do not store references to the returned value. Make copies instead.
func (*Args) PeekMultiBytes ¶
PeekMultiBytes returns all the arg values for the given key.
func (*Args) QueryString ¶
QueryString returns query string for the args.
The returned value is valid until the Args is reused or released (ReleaseArgs). Do not store references to the returned value. Make copies instead.
func (*Args) SetBytesKNoValue ¶
SetBytesKNoValue sets 'key' argument.
func (*Args) SetBytesKV ¶
SetBytesKV sets 'key=value' argument.
func (*Args) SetNoValue ¶
SetNoValue sets only 'key' as argument without the '='.
Only key in argument, like key1&key2.
func (*Args) SetUintBytes ¶
SetUintBytes sets uint value for the given key.
func (*Args) Sort ¶
Sort sorts Args by key and then value using 'f' as comparison function.
For example args.Sort(bytes.Compare).
type Context ¶
type Context struct {
Request *Request
Response *Response
Params map[string]string
Values map[string]any
Conn metanet.Conn
// contains filtered or unexported fields
}
Context represents HTTP request context.
func NewContext ¶
NewContext creates a new context.
func (*Context) NotFound ¶
func (c *Context) NotFound()
NotFound resets response and sets '404 Not Found' response status code.
type Cookie ¶
type Cookie struct {
// contains filtered or unexported fields
}
Cookie represents HTTP response cookie.
Do not copy Cookie objects. Create new object and use CopyTo instead.
Cookie instance MUST NOT be used from concurrently running goroutines.
func AcquireCookie ¶
func AcquireCookie() *Cookie
AcquireCookie returns an empty Cookie object from the pool.
The returned object may be returned back to the pool with ReleaseCookie. This allows reducing GC load.
func (*Cookie) AppendBytes ¶
AppendBytes appends cookie representation to dst and returns the extended dst.
func (*Cookie) Cookie ¶
Cookie returns cookie representation.
The returned value is valid until the Cookie reused or released (ReleaseCookie). Do not store references to the returned value. Make copies instead.
func (*Cookie) Domain ¶
Domain returns cookie domain.
The returned value is valid until the Cookie reused or released (ReleaseCookie). Do not store references to the returned value. Make copies instead.
func (*Cookie) Expire ¶
Expire returns cookie expiration time.
CookieExpireUnlimited is returned if cookie doesn't expire.
func (*Cookie) Key ¶
Key returns cookie name.
The returned value is valid until the Cookie reused or released (ReleaseCookie). Do not store references to the returned value. Make copies instead.
func (*Cookie) MaxAge ¶
MaxAge returns the seconds until the cookie is meant to expire or 0 if no max age.
func (*Cookie) ParseBytes ¶
ParseBytes parses Set-Cookie header.
func (*Cookie) Partitioned ¶
Partitioned returns true if the cookie is partitioned.
func (*Cookie) SameSite ¶
func (c *Cookie) SameSite() CookieSameSite
SameSite returns the SameSite mode.
func (*Cookie) SetDomainBytes ¶
SetDomainBytes sets cookie domain.
func (*Cookie) SetExpire ¶
SetExpire sets cookie expiration time.
Set expiration time to CookieExpireDelete for expiring (deleting) the cookie on the client.
By default cookie lifetime is limited by browser session.
func (*Cookie) SetHTTPOnly ¶
SetHTTPOnly sets cookie's httpOnly flag to the given value.
func (*Cookie) SetMaxAge ¶
SetMaxAge sets cookie expiration time based on seconds. This takes precedence over any absolute expiry set on the cookie.
'max-age' is set when the maxAge is non-zero. That is, if maxAge = 0, the 'max-age' is unset. If maxAge < 0, it indicates that the cookie should be deleted immediately, equivalent to 'max-age=0'. This behavior is consistent with the Go standard library's net/http package.
func (*Cookie) SetPartitioned ¶
SetPartitioned sets the cookie's Partitioned flag to the given value. Set value Partitioned to true will set Secure to true and Path to / also to avoid browser rejection.
func (*Cookie) SetPathBytes ¶
SetPathBytes sets cookie path.
func (*Cookie) SetSameSite ¶
func (c *Cookie) SetSameSite(mode CookieSameSite)
SetSameSite sets the cookie's SameSite flag to the given value. Set value CookieSameSiteNoneMode will set Secure to true also to avoid browser rejection.
func (*Cookie) SetValueBytes ¶
SetValueBytes sets cookie value.
type CookieSameSite ¶
type CookieSameSite int
CookieSameSite is an enum for the mode in which the SameSite flag should be set for the given cookie. See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.
const ( // CookieSameSiteDisabled removes the SameSite flag. CookieSameSiteDisabled CookieSameSite = iota // CookieSameSiteDefaultMode sets the SameSite flag. CookieSameSiteDefaultMode // CookieSameSiteLaxMode sets the SameSite flag with the "Lax" parameter. CookieSameSiteLaxMode // CookieSameSiteStrictMode sets the SameSite flag with the "Strict" parameter. CookieSameSiteStrictMode // CookieSameSiteNoneMode sets the SameSite flag with the "None" parameter. // See https://tools.ietf.org/html/draft-west-cookie-incrementalism-00 CookieSameSiteNoneMode // third-party cookies are phasing out, use Partitioned cookies instead )
type ErrNothingRead ¶
type ErrNothingRead struct {
// contains filtered or unexported fields
}
ErrNothingRead is returned when a keep-alive connection is closed, either because the remote closed it or because of a read timeout.
type ErrSmallBuffer ¶
type ErrSmallBuffer struct {
// contains filtered or unexported fields
}
ErrSmallBuffer is returned when the provided buffer size is too small for reading request and/or response headers.
ReadBufferSize value from Server or clients should reduce the number of such errors.
type EscapeError ¶
type EscapeError string
func (EscapeError) Error ¶
func (e EscapeError) Error() string
type InvalidHostError ¶
type InvalidHostError string
func (InvalidHostError) Error ¶
func (e InvalidHostError) Error() string
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
MiddlewareFunc represents a middleware function.
type NewWriterFunc ¶
NewWriterFunc must return new writer that will be wrapped into stackless writer.
type Params ¶
type Params []Param
Params is a slice of Param
type ParseState ¶
type ParseState int
ParseState HTTP protocol state
const ( ParseStateHeader ParseState = iota ParseStateBody ParseStateComplete )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser HTTP parser
func AcquireRequestParser ¶
func AcquireRequestParser() *Parser
AcquireRequestParser Get request parser
func AcquireResponseParser ¶
func AcquireResponseParser() *Parser
AcquireResponseParser Get response parser
func (*Parser) GetResponse ¶
type Request ¶
type Request struct {
Header RequestHeader
// contains filtered or unexported fields
}
Request represents HTTP request.
func AcquireRequest ¶
func AcquireRequest() *Request
AcquireRequest returns an empty Request instance from request pool.
func (*Request) AppendBodyRaw ¶
AppendBodyRaw appends data to request body.
func (*Request) BodyStream ¶
BodyStream returns io.Reader.
You must CloseBodyStream or ReleaseRequest after you use it.
func (*Request) BodyString ¶
BodyString returns request body as string.
func (*Request) BodyWriter ¶
BodyWriter returns writer for populating request body.
func (*Request) CloseBodyStream ¶
CloseBodyStream closes body stream.
func (*Request) HostString ¶
HostString returns request host as string.
func (*Request) IsBodyStream ¶
IsBodyStream returns true if body is set via SetBodyStream*.
func (*Request) MethodString ¶
MethodString returns request method as string.
func (*Request) RequestURI ¶
RequestURI returns request URI.
func (*Request) SetBodyRaw ¶
SetBodyRaw sets request body.
func (*Request) SetBodyStream ¶
SetBodyStream sets request body stream and, optionally body size.
If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes before returning io.EOF.
If bodySize < 0, then bodyStream is read until io.EOF.
bodyStream.Close() is called after finishing reading all body data if it implements io.Closer.
See also SetBodyStreamWriter.
func (*Request) SetBodyStreamWriter ¶
func (req *Request) SetBodyStreamWriter(sw StreamWriter)
SetBodyStreamWriter registers the given sw for populating request body.
This function may be used in the following cases:
- if request body is too big (more than 10MB).
- if request body is streamed from slow external sources.
- if request body must be streamed to the server in chunks (aka `http client push` or `chunked transfer-encoding`).
See also SetBodyStream.
func (*Request) SetRequestURI ¶
SetRequestURI sets request URI.
func (*Request) WriteDeflate ¶
WriteDeflate writes deflated request body.
func (*Request) WriteDeflateLevel ¶
WriteDeflateLevel writes deflated request body with specified compression level.
func (*Request) WriteGzipLevel ¶
WriteGzipLevel writes gzipped request body with specified compression level.
type RequestHeader ¶
type RequestHeader struct {
// contains filtered or unexported fields
}
RequestHeader represents HTTP request header.
It is forbidden copying RequestHeader instances. Create new instances instead and use CopyTo.
RequestHeader instance MUST NOT be used from concurrently running goroutines.
func (*RequestHeader) Add ¶
func (h *RequestHeader) Add(key, value string)
Add adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked request body.
func (*RequestHeader) AddBytesK ¶
func (h *RequestHeader) AddBytesK(key []byte, value string)
AddBytesK adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesK for setting a single header for the given key.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked request body.
func (*RequestHeader) AddBytesKV ¶
func (h *RequestHeader) AddBytesKV(key, value []byte)
AddBytesKV adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesKV for setting a single header for the given key.
the Content-Type, Content-Length, Connection, Transfer-Encoding, Host and User-Agent headers can only be set once and will overwrite the previous value, while the Cookie header will not clear previous cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked request body.
func (*RequestHeader) AddBytesV ¶
func (h *RequestHeader) AddBytesV(key string, value []byte)
AddBytesV adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesV for setting a single header for the given key.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked request body.
func (*RequestHeader) AddTrailer ¶
AddTrailer add Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*RequestHeader) AddTrailerBytes ¶
AddTrailerBytes add Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*RequestHeader) All ¶
func (h *RequestHeader) All() iter.Seq2[[]byte, []byte]
All returns an iterator over key-value pairs in h.
The key and value may invalid outside the iteration loop. Copy key and/or value contents for each iteration if you need retaining them.
To get the headers in order they were received use AllInOrder.
func (*RequestHeader) AllInOrder ¶
func (h *RequestHeader) AllInOrder() iter.Seq2[[]byte, []byte]
AllInOrder returns an iterator over key-value pairs in h in the order they were received.
The key and value may invalid outside the iteration loop. Copy key and/or value contents for each iteration if you need retaining them.
The returned iterator is slightly slower than All because it has to reparse the raw headers to get the order.
func (*RequestHeader) AppendBytes ¶
func (h *RequestHeader) AppendBytes(dst []byte) []byte
AppendBytes appends request header representation to dst and returns the extended dst.
func (*RequestHeader) ConnectionClose ¶
func (h *RequestHeader) ConnectionClose() bool
ConnectionClose returns true if 'Connection: close' header is set.
func (*RequestHeader) ConnectionUpgrade ¶
func (h *RequestHeader) ConnectionUpgrade() bool
ConnectionUpgrade returns true if 'Connection: Upgrade' header is set.
func (*RequestHeader) ContentEncoding ¶
func (h *RequestHeader) ContentEncoding() []byte
ContentEncoding returns Content-Encoding header value.
func (*RequestHeader) ContentLength ¶
func (h *RequestHeader) ContentLength() int
ContentLength returns Content-Length header value.
It may be negative: -1 means Transfer-Encoding: chunked. -2 means Transfer-Encoding: identity.
func (*RequestHeader) ContentType ¶
func (h *RequestHeader) ContentType() []byte
ContentType returns Content-Type header value.
func (*RequestHeader) Cookie ¶
func (h *RequestHeader) Cookie(key string) []byte
Cookie returns cookie for the given key.
func (*RequestHeader) CookieBytes ¶
func (h *RequestHeader) CookieBytes(key []byte) []byte
CookieBytes returns cookie for the given key.
func (*RequestHeader) Cookies ¶
func (h *RequestHeader) Cookies() iter.Seq2[[]byte, []byte]
Cookies returns an iterator over key-value pairs request cookie in h.
The key and value may invalid outside the iteration loop. Copy key and/or value contents for each iteration if you need retaining them.
func (*RequestHeader) CopyTo ¶
func (h *RequestHeader) CopyTo(dst *RequestHeader)
CopyTo copies all the headers to dst.
func (*RequestHeader) Del ¶
func (h *RequestHeader) Del(key string)
Del deletes header with the given key.
func (*RequestHeader) DelAllCookies ¶
func (h *RequestHeader) DelAllCookies()
DelAllCookies removes all the cookies from request headers.
func (*RequestHeader) DelBytes ¶
func (h *RequestHeader) DelBytes(key []byte)
DelBytes deletes header with the given key.
func (*RequestHeader) DelCookie ¶
func (h *RequestHeader) DelCookie(key string)
DelCookie removes cookie under the given key.
func (*RequestHeader) DelCookieBytes ¶
func (h *RequestHeader) DelCookieBytes(key []byte)
DelCookieBytes removes cookie under the given key.
func (*RequestHeader) DisableNormalizing ¶
func (h *RequestHeader) DisableNormalizing()
DisableNormalizing disables header names' normalization.
By default all the header names are normalized by uppercasing the first letter and all the first letters following dashes, while lowercasing all the other letters. Examples:
- CONNECTION -> Connection
- conteNT-tYPE -> Content-Type
- foo-bar-baz -> Foo-Bar-Baz
Disable header names' normalization only if know what are you doing.
func (*RequestHeader) DisableSpecialHeader ¶
func (h *RequestHeader) DisableSpecialHeader()
DisableSpecialHeader disables special header processing. fasthttp will not set any special headers for you, such as Host, Content-Type, User-Agent, etc. You must set everything yourself. If RequestHeader.Read() is called, special headers will be ignored. This can be used to control case and order of special headers. This is generally not recommended.
func (*RequestHeader) EnableNormalizing ¶
func (h *RequestHeader) EnableNormalizing()
EnableNormalizing enables header names' normalization.
Header names are normalized by uppercasing the first letter and all the first letters following dashes, while lowercasing all the other letters. Examples:
- CONNECTION -> Connection
- conteNT-tYPE -> Content-Type
- foo-bar-baz -> Foo-Bar-Baz
This is enabled by default unless disabled using DisableNormalizing().
func (*RequestHeader) EnableSpecialHeader ¶
func (h *RequestHeader) EnableSpecialHeader()
EnableSpecialHeader enables special header processing. fasthttp will send Host, Content-Type, User-Agent, etc headers for you. This is suggested and enabled by default.
func (*RequestHeader) Get ¶
func (h *RequestHeader) Get(key string) string
func (*RequestHeader) HasAcceptEncoding ¶
func (h *RequestHeader) HasAcceptEncoding(acceptEncoding string) bool
HasAcceptEncoding returns true if the header contains the given Accept-Encoding value.
func (*RequestHeader) HasAcceptEncodingBytes ¶
func (h *RequestHeader) HasAcceptEncodingBytes(acceptEncoding []byte) bool
HasAcceptEncodingBytes returns true if the header contains the given Accept-Encoding value.
func (*RequestHeader) Header ¶
func (h *RequestHeader) Header() []byte
Header returns request header representation.
Headers that set as Trailer will not represent. Use TrailerHeader for trailers.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*RequestHeader) IsConnect ¶
func (h *RequestHeader) IsConnect() bool
IsConnect returns true if request method is CONNECT.
func (*RequestHeader) IsDelete ¶
func (h *RequestHeader) IsDelete() bool
IsDelete returns true if request method is DELETE.
func (*RequestHeader) IsGet ¶
func (h *RequestHeader) IsGet() bool
IsGet returns true if request method is GET.
func (*RequestHeader) IsHTTP11 ¶
func (h *RequestHeader) IsHTTP11() bool
IsHTTP11 returns true if the header is HTTP/1.1.
func (*RequestHeader) IsHead ¶
func (h *RequestHeader) IsHead() bool
IsHead returns true if request method is HEAD.
func (*RequestHeader) IsOptions ¶
func (h *RequestHeader) IsOptions() bool
IsOptions returns true if request method is OPTIONS.
func (*RequestHeader) IsPatch ¶
func (h *RequestHeader) IsPatch() bool
IsPatch returns true if request method is PATCH.
func (*RequestHeader) IsPost ¶
func (h *RequestHeader) IsPost() bool
IsPost returns true if request method is POST.
func (*RequestHeader) IsPut ¶
func (h *RequestHeader) IsPut() bool
IsPut returns true if request method is PUT.
func (*RequestHeader) IsTrace ¶
func (h *RequestHeader) IsTrace() bool
IsTrace returns true if request method is TRACE.
func (*RequestHeader) Len ¶
func (h *RequestHeader) Len() int
Len returns the number of headers set, i.e. the number of times f is called in VisitAll.
func (*RequestHeader) Method ¶
func (h *RequestHeader) Method() []byte
Method returns HTTP request method.
func (*RequestHeader) MultipartFormBoundary ¶
func (h *RequestHeader) MultipartFormBoundary() []byte
MultipartFormBoundary returns boundary part from 'multipart/form-data; boundary=...' Content-Type.
func (*RequestHeader) Peek ¶
func (h *RequestHeader) Peek(key string) []byte
Peek returns header value for the given key.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*RequestHeader) PeekAll ¶
func (h *RequestHeader) PeekAll(key string) [][]byte
PeekAll returns all header value for the given key.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*RequestHeader) PeekBytes ¶
func (h *RequestHeader) PeekBytes(key []byte) []byte
PeekBytes returns header value for the given key.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*RequestHeader) PeekKeys ¶
func (h *RequestHeader) PeekKeys() [][]byte
PeekKeys return all header keys.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*RequestHeader) PeekTrailerKeys ¶
func (h *RequestHeader) PeekTrailerKeys() [][]byte
PeekTrailerKeys return all trailer keys.
The returned value is valid until the request is released, either though ReleaseResponse or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*RequestHeader) Protocol ¶
func (h *RequestHeader) Protocol() []byte
Protocol returns HTTP protocol.
func (*RequestHeader) RawHeaders ¶
func (h *RequestHeader) RawHeaders() []byte
RawHeaders returns raw header key/value bytes.
Depending on server configuration, header keys may be normalized to capital-case in place.
This copy is set aside during parsing, so empty slice is returned for all cases where parsing did not happen. Similarly, request line is not stored during parsing and can not be returned.
The slice is not safe to use after the handler returns.
func (*RequestHeader) Read ¶
func (h *RequestHeader) Read(r *bufio.Reader) error
Read reads request header from r.
io.EOF is returned if r is closed before reading the first header byte.
func (*RequestHeader) ReadTrailer ¶
ReadTrailer reads response trailer header from r.
io.EOF is returned if r is closed before reading the first byte.
func (*RequestHeader) Referer ¶
func (h *RequestHeader) Referer() []byte
Referer returns Referer header value.
func (*RequestHeader) RequestURI ¶
func (h *RequestHeader) RequestURI() []byte
RequestURI returns RequestURI from the first HTTP request line.
func (*RequestHeader) ResetConnectionClose ¶
func (h *RequestHeader) ResetConnectionClose()
ResetConnectionClose clears 'Connection: close' header if it exists.
func (*RequestHeader) Set ¶
func (h *RequestHeader) Set(key, value string)
Set sets the given 'key: value' header.
Please note that the Cookie header will not clear previous cookies, delete cookies before calling in order to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked request body.
Use Add for setting multiple header values under the same key.
func (*RequestHeader) SetByteRange ¶
func (h *RequestHeader) SetByteRange(startPos, endPos int)
SetByteRange sets 'Range: bytes=startPos-endPos' header.
- If startPos is negative, then 'bytes=-startPos' value is set.
- If endPos is negative, then 'bytes=startPos-' value is set.
func (*RequestHeader) SetBytesK ¶
func (h *RequestHeader) SetBytesK(key []byte, value string)
SetBytesK sets the given 'key: value' header.
Please note that the Cookie header will not clear previous cookies, delete cookies before calling in order to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked request body.
Use AddBytesK for setting multiple header values under the same key.
func (*RequestHeader) SetBytesKV ¶
func (h *RequestHeader) SetBytesKV(key, value []byte)
SetBytesKV sets the given 'key: value' header.
Please note that the Cookie header will not clear previous cookies, delete cookies before calling in order to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked request body.
Use AddBytesKV for setting multiple header values under the same key.
func (*RequestHeader) SetBytesV ¶
func (h *RequestHeader) SetBytesV(key string, value []byte)
SetBytesV sets the given 'key: value' header.
Please note that the Cookie header will not clear previous cookies, delete cookies before calling in order to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked request body.
Use AddBytesV for setting multiple header values under the same key.
func (*RequestHeader) SetCanonical ¶
func (h *RequestHeader) SetCanonical(key, value []byte)
SetCanonical sets the given 'key: value' header assuming that key is in canonical form.
Please note that the Cookie header will not clear previous cookies, delete cookies before calling in order to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked request body.
func (*RequestHeader) SetConnectionClose ¶
func (h *RequestHeader) SetConnectionClose()
SetConnectionClose sets 'Connection: close' header.
func (*RequestHeader) SetContentEncoding ¶
func (h *RequestHeader) SetContentEncoding(contentEncoding string)
SetContentEncoding sets Content-Encoding header value.
func (*RequestHeader) SetContentEncodingBytes ¶
func (h *RequestHeader) SetContentEncodingBytes(contentEncoding []byte)
SetContentEncodingBytes sets Content-Encoding header value.
func (*RequestHeader) SetContentLength ¶
func (h *RequestHeader) SetContentLength(contentLength int)
SetContentLength sets Content-Length header value.
Negative content-length sets 'Transfer-Encoding: chunked' header.
func (*RequestHeader) SetContentType ¶
func (h *RequestHeader) SetContentType(contentType string)
SetContentType sets Content-Type header value.
func (*RequestHeader) SetContentTypeBytes ¶
func (h *RequestHeader) SetContentTypeBytes(contentType []byte)
SetContentTypeBytes sets Content-Type header value.
func (*RequestHeader) SetCookie ¶
func (h *RequestHeader) SetCookie(key, value string)
SetCookie sets 'key: value' cookies.
func (*RequestHeader) SetCookieBytesK ¶
func (h *RequestHeader) SetCookieBytesK(key []byte, value string)
SetCookieBytesK sets 'key: value' cookies.
func (*RequestHeader) SetCookieBytesKV ¶
func (h *RequestHeader) SetCookieBytesKV(key, value []byte)
SetCookieBytesKV sets 'key: value' cookies.
func (*RequestHeader) SetHost ¶
func (h *RequestHeader) SetHost(host string)
SetHost sets Host header value.
func (*RequestHeader) SetHostBytes ¶
func (h *RequestHeader) SetHostBytes(host []byte)
SetHostBytes sets Host header value.
func (*RequestHeader) SetMethod ¶
func (h *RequestHeader) SetMethod(method string)
SetMethod sets HTTP request method.
func (*RequestHeader) SetMethodBytes ¶
func (h *RequestHeader) SetMethodBytes(method []byte)
SetMethodBytes sets HTTP request method.
func (*RequestHeader) SetMultipartFormBoundary ¶
func (h *RequestHeader) SetMultipartFormBoundary(boundary string)
SetMultipartFormBoundary sets the following Content-Type: 'multipart/form-data; boundary=...' where ... is substituted by the given boundary.
func (*RequestHeader) SetMultipartFormBoundaryBytes ¶
func (h *RequestHeader) SetMultipartFormBoundaryBytes(boundary []byte)
SetMultipartFormBoundaryBytes sets the following Content-Type: 'multipart/form-data; boundary=...' where ... is substituted by the given boundary.
func (*RequestHeader) SetNoDefaultContentType ¶
func (h *RequestHeader) SetNoDefaultContentType(noDefaultContentType bool)
SetNoDefaultContentType allows you to control if a default Content-Type header will be set (false) or not (true).
func (*RequestHeader) SetNonSpecial ¶
func (h *RequestHeader) SetNonSpecial(key, value []byte)
SetNonSpecial directly put into map i.e. not a basic header.
func (*RequestHeader) SetProtocol ¶
func (h *RequestHeader) SetProtocol(protocol string)
SetProtocol sets HTTP request protocol.
func (*RequestHeader) SetProtocolBytes ¶
func (h *RequestHeader) SetProtocolBytes(protocol []byte)
SetProtocolBytes sets HTTP request protocol.
func (*RequestHeader) SetReferer ¶
func (h *RequestHeader) SetReferer(referer string)
SetReferer sets Referer header value.
func (*RequestHeader) SetRefererBytes ¶
func (h *RequestHeader) SetRefererBytes(referer []byte)
SetRefererBytes sets Referer header value.
func (*RequestHeader) SetRequestURI ¶
func (h *RequestHeader) SetRequestURI(requestURI string)
SetRequestURI sets RequestURI for the first HTTP request line. RequestURI must be properly encoded. Use URI.RequestURI for constructing proper RequestURI if unsure.
func (*RequestHeader) SetRequestURIBytes ¶
func (h *RequestHeader) SetRequestURIBytes(requestURI []byte)
SetRequestURIBytes sets RequestURI for the first HTTP request line. RequestURI must be properly encoded. Use URI.RequestURI for constructing proper RequestURI if unsure.
func (*RequestHeader) SetTrailer ¶
SetTrailer sets header Trailer value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*RequestHeader) SetTrailerBytes ¶
SetTrailerBytes sets Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*RequestHeader) SetUserAgent ¶
func (h *RequestHeader) SetUserAgent(userAgent string)
SetUserAgent sets User-Agent header value.
func (*RequestHeader) SetUserAgentBytes ¶
func (h *RequestHeader) SetUserAgentBytes(userAgent []byte)
SetUserAgentBytes sets User-Agent header value.
func (*RequestHeader) String ¶
func (h *RequestHeader) String() string
String returns request header representation.
func (*RequestHeader) TrailerHeader ¶
func (h *RequestHeader) TrailerHeader() []byte
TrailerHeader returns request trailer header representation.
Trailers will only be received with chunked transfer.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*RequestHeader) Trailers ¶
Trailers returns an iterator over trailers in h.
The value of trailer may invalid outside the iteration loop.
func (*RequestHeader) UserAgent ¶
func (h *RequestHeader) UserAgent() []byte
UserAgent returns User-Agent header value.
func (*RequestHeader) VisitAll
deprecated
func (h *RequestHeader) VisitAll(f func(key, value []byte))
VisitAll calls f for each header.
f must not retain references to key and/or value after returning. Copy key and/or value contents before returning if you need retaining them.
To get the headers in order they were received use VisitAllInOrder.
Deprecated: Use All instead.
func (*RequestHeader) VisitAllCookie
deprecated
func (h *RequestHeader) VisitAllCookie(f func(key, value []byte))
VisitAllCookie calls f for each request cookie.
f must not retain references to key and/or value after returning.
Deprecated: Use Cookies instead.
func (*RequestHeader) VisitAllInOrder
deprecated
func (h *RequestHeader) VisitAllInOrder(f func(key, value []byte))
VisitAllInOrder calls f for each header in the order they were received.
f must not retain references to key and/or value after returning. Copy key and/or value contents before returning if you need retaining them.
This function is slightly slower than VisitAll because it has to reparse the raw headers to get the order.
Deprecated: Use AllInOrder instead.
func (*RequestHeader) VisitAllTrailer
deprecated
func (h *RequestHeader) VisitAllTrailer(f func(value []byte))
VisitAllTrailer calls f for each response Trailer.
f must not retain references to value after returning.
Deprecated: Use Trailers instead.
type Response ¶
type Response struct {
Header ResponseHeader
// contains filtered or unexported fields
}
Response represents HTTP response.
func AcquireResponse ¶
func AcquireResponse() *Response
AcquireResponse returns an empty Response instance from response pool.
func (*Response) AppendBody ¶
AppendBody appends data to response body.
func (*Response) AppendBodyRaw ¶
AppendBodyRaw appends data to response body.
func (*Response) AppendBodyString ¶
AppendBodyString appends string to response body.
func (*Response) BodyStream ¶
BodyStream returns io.Reader.
You must CloseBodyStream or ReleaseResponse after you use it.
func (*Response) BodyString ¶
BodyString returns response body as string.
func (*Response) BodyWriter ¶
BodyWriter returns writer for populating response body.
func (*Response) CloseBodyStream ¶
CloseBodyStream closes body stream.
func (*Response) ConnectionClose ¶
ConnectionClose returns true if 'Connection: close' header is set.
func (*Response) ContentLength ¶
ContentLength returns Content-Length header value.
func (*Response) ContentType ¶
ContentType returns Content-Type header value.
func (*Response) IsBodyStream ¶
IsBodyStream returns true if body is set via SetBodyStream*.
func (*Response) SetBodyRaw ¶
SetBodyRaw sets response body.
func (*Response) SetBodyStream ¶
SetBodyStream sets response body stream and, optionally body size.
If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes before returning io.EOF.
If bodySize < 0, then bodyStream is read until io.EOF.
bodyStream.Close() is called after finishing reading all body data if it implements io.Closer.
See also SetBodyStreamWriter.
func (*Response) SetBodyStreamWriter ¶
func (resp *Response) SetBodyStreamWriter(sw StreamWriter)
SetBodyStreamWriter registers the given sw for populating response body.
This function may be used in the following cases:
- if response body is too big (more than 10MB).
- if response body is streamed from slow external sources.
- if response body must be streamed to the client in chunks (aka `http server push` or `chunked transfer-encoding`).
See also SetBodyStream.
func (*Response) SetConnectionClose ¶
func (resp *Response) SetConnectionClose()
SetConnectionClose sets 'Connection: close' header.
func (*Response) SetContentLength ¶
SetContentLength sets Content-Length header.
func (*Response) SetContentType ¶
SetContentType sets Content-Type header.
func (*Response) SetStatusCode ¶
SetStatusCode sets response status code.
func (*Response) SetText ¶
SetText sets response body as plain text and sets appropriate Content-Type.
func (*Response) StatusCode ¶
StatusCode returns response status code.
func (*Response) WriteDeflate ¶
WriteDeflate writes deflated response body.
func (*Response) WriteDeflateLevel ¶
WriteDeflateLevel writes deflated response body with specified compression level.
func (*Response) WriteGzipLevel ¶
WriteGzipLevel writes gzipped response body with specified compression level.
type ResponseHeader ¶
type ResponseHeader struct {
// contains filtered or unexported fields
}
ResponseHeader represents HTTP response header.
It is forbidden copying ResponseHeader instances. Create new instances instead and use CopyTo.
ResponseHeader instance MUST NOT be used from concurrently running goroutines.
func (*ResponseHeader) Add ¶
func (h *ResponseHeader) Add(key, value string)
Add adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.
the Content-Type, Content-Length, Connection, Server, Transfer-Encoding and Date headers can only be set once and will overwrite the previous value, while Set-Cookie will not clear previous cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked response body.
func (*ResponseHeader) AddBytesK ¶
func (h *ResponseHeader) AddBytesK(key []byte, value string)
AddBytesK adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesK for setting a single header for the given key.
the Content-Type, Content-Length, Connection, Server, Transfer-Encoding and Date headers can only be set once and will overwrite the previous value, while Set-Cookie will not clear previous cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked response body.
func (*ResponseHeader) AddBytesKV ¶
func (h *ResponseHeader) AddBytesKV(key, value []byte)
AddBytesKV adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesKV for setting a single header for the given key.
the Content-Type, Content-Length, Connection, Server, Transfer-Encoding and Date headers can only be set once and will overwrite the previous value, while the Set-Cookie header will not clear previous cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked response body.
func (*ResponseHeader) AddBytesV ¶
func (h *ResponseHeader) AddBytesV(key string, value []byte)
AddBytesV adds the given 'key: value' header.
Multiple headers with the same key may be added with this function. Use SetBytesV for setting a single header for the given key.
the Content-Type, Content-Length, Connection, Server, Transfer-Encoding and Date headers can only be set once and will overwrite the previous value, while Set-Cookie will not clear previous cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see AddTrailer for more details), it will be sent after the chunked response body.
func (*ResponseHeader) AddTrailer ¶
AddTrailer add Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*ResponseHeader) AddTrailerBytes ¶
AddTrailerBytes add Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*ResponseHeader) All ¶
func (h *ResponseHeader) All() iter.Seq2[[]byte, []byte]
All returns an iterator over key-value pairs in h.
The key and value may invalid outside the iteration loop. Copy key and/or value contents for each iteration if you need retaining them.
func (*ResponseHeader) AppendBytes ¶
func (h *ResponseHeader) AppendBytes(dst []byte) []byte
AppendBytes appends response header representation to dst and returns the extended dst.
func (*ResponseHeader) ConnectionClose ¶
func (h *ResponseHeader) ConnectionClose() bool
ConnectionClose returns true if 'Connection: close' header is set.
func (*ResponseHeader) ConnectionUpgrade ¶
func (h *ResponseHeader) ConnectionUpgrade() bool
ConnectionUpgrade returns true if 'Connection: Upgrade' header is set.
func (*ResponseHeader) ContentEncoding ¶
func (h *ResponseHeader) ContentEncoding() []byte
ContentEncoding returns Content-Encoding header value.
func (*ResponseHeader) ContentLength ¶
func (h *ResponseHeader) ContentLength() int
ContentLength returns Content-Length header value.
It may be negative: -1 means Transfer-Encoding: chunked. -2 means Transfer-Encoding: identity.
func (*ResponseHeader) ContentType ¶
func (h *ResponseHeader) ContentType() []byte
ContentType returns Content-Type header value.
func (*ResponseHeader) Cookie ¶
func (h *ResponseHeader) Cookie(cookie *Cookie) bool
Cookie fills cookie for the given cookie.Key.
Returns false if cookie with the given cookie.Key is missing.
func (*ResponseHeader) Cookies ¶
func (h *ResponseHeader) Cookies() iter.Seq2[[]byte, []byte]
Cookies returns an iterator over key-value paired response cookie in h.
Cookie name is passed in key and the whole Set-Cookie header value is passed in value for each iteration. Value may be parsed with Cookie.ParseBytes().
The key and value may invalid outside the iteration loop. Copy key and/or value contents for each iteration if you need retaining them.
func (*ResponseHeader) CopyTo ¶
func (h *ResponseHeader) CopyTo(dst *ResponseHeader)
CopyTo copies all the headers to dst.
func (*ResponseHeader) Del ¶
func (h *ResponseHeader) Del(key string)
Del deletes header with the given key.
func (*ResponseHeader) DelAllCookies ¶
func (h *ResponseHeader) DelAllCookies()
DelAllCookies removes all the cookies from response headers.
func (*ResponseHeader) DelBytes ¶
func (h *ResponseHeader) DelBytes(key []byte)
DelBytes deletes header with the given key.
func (*ResponseHeader) DelClientCookie ¶
func (h *ResponseHeader) DelClientCookie(key string)
DelClientCookie instructs the client to remove the given cookie. This doesn't work for a cookie with specific domain or path, you should delete it manually like:
c := AcquireCookie()
c.SetKey(key)
c.SetDomain("example.com")
c.SetPath("/path")
c.SetExpire(CookieExpireDelete)
h.SetCookie(c)
ReleaseCookie(c)
Use DelCookie if you want just removing the cookie from response header.
func (*ResponseHeader) DelClientCookieBytes ¶
func (h *ResponseHeader) DelClientCookieBytes(key []byte)
DelClientCookieBytes instructs the client to remove the given cookie. This doesn't work for a cookie with specific domain or path, you should delete it manually like:
c := AcquireCookie()
c.SetKey(key)
c.SetDomain("example.com")
c.SetPath("/path")
c.SetExpire(CookieExpireDelete)
h.SetCookie(c)
ReleaseCookie(c)
Use DelCookieBytes if you want just removing the cookie from response header.
func (*ResponseHeader) DelCookie ¶
func (h *ResponseHeader) DelCookie(key string)
DelCookie removes cookie under the given key from response header.
Note that DelCookie doesn't remove the cookie from the client. Use DelClientCookie instead.
func (*ResponseHeader) DelCookieBytes ¶
func (h *ResponseHeader) DelCookieBytes(key []byte)
DelCookieBytes removes cookie under the given key from response header.
Note that DelCookieBytes doesn't remove the cookie from the client. Use DelClientCookieBytes instead.
func (*ResponseHeader) DisableNormalizing ¶
func (h *ResponseHeader) DisableNormalizing()
DisableNormalizing disables header names' normalization.
By default all the header names are normalized by uppercasing the first letter and all the first letters following dashes, while lowercasing all the other letters. Examples:
- CONNECTION -> Connection
- conteNT-tYPE -> Content-Type
- foo-bar-baz -> Foo-Bar-Baz
Disable header names' normalization only if know what are you doing.
func (*ResponseHeader) EnableNormalizing ¶
func (h *ResponseHeader) EnableNormalizing()
EnableNormalizing enables header names' normalization.
Header names are normalized by uppercasing the first letter and all the first letters following dashes, while lowercasing all the other letters. Examples:
- CONNECTION -> Connection
- conteNT-tYPE -> Content-Type
- foo-bar-baz -> Foo-Bar-Baz
This is enabled by default unless disabled using DisableNormalizing().
func (*ResponseHeader) Header ¶
func (h *ResponseHeader) Header() []byte
Header returns response header representation.
Headers that set as Trailer will not represent. Use TrailerHeader for trailers.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) IsHTTP11 ¶
func (h *ResponseHeader) IsHTTP11() bool
IsHTTP11 returns true if the header is HTTP/1.1.
func (*ResponseHeader) Len ¶
func (h *ResponseHeader) Len() int
Len returns the number of headers set, i.e. the number of times f is called in VisitAll.
func (*ResponseHeader) Peek ¶
func (h *ResponseHeader) Peek(key string) []byte
Peek returns header value for the given key.
The returned value is valid until the response is released, either though ReleaseResponse or your request handler returning. Do not store references to the returned value. Make copies instead.
func (*ResponseHeader) PeekAll ¶
func (h *ResponseHeader) PeekAll(key string) [][]byte
PeekAll returns all header value for the given key.
The returned value is valid until the request is released, either though ReleaseResponse or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) PeekBytes ¶
func (h *ResponseHeader) PeekBytes(key []byte) []byte
PeekBytes returns header value for the given key.
The returned value is valid until the response is released, either though ReleaseResponse or your request handler returning. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) PeekCookie ¶
func (h *ResponseHeader) PeekCookie(key string) []byte
PeekCookie is able to returns cookie by a given key from response.
func (*ResponseHeader) PeekKeys ¶
func (h *ResponseHeader) PeekKeys() [][]byte
PeekKeys return all header keys.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) PeekTrailerKeys ¶
func (h *ResponseHeader) PeekTrailerKeys() [][]byte
PeekTrailerKeys return all trailer keys.
The returned value is valid until the request is released, either though ReleaseResponse or your request handler returning. Any future calls to the Peek* will modify the returned value. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) Protocol ¶
func (h *ResponseHeader) Protocol() []byte
Protocol returns HTTP protocol.
func (*ResponseHeader) Read ¶
func (h *ResponseHeader) Read(r *bufio.Reader) error
Read reads response header from r.
io.EOF is returned if r is closed before reading the first header byte.
func (*ResponseHeader) ReadTrailer ¶
ReadTrailer reads response trailer header from r.
io.EOF is returned if r is closed before reading the first byte.
func (*ResponseHeader) ResetConnectionClose ¶
func (h *ResponseHeader) ResetConnectionClose()
ResetConnectionClose clears 'Connection: close' header if it exists.
func (*ResponseHeader) Server ¶
func (h *ResponseHeader) Server() []byte
Server returns Server header value.
func (*ResponseHeader) Set ¶
func (h *ResponseHeader) Set(key, value string)
Set sets the given 'key: value' header.
Please note that the Set-Cookie header will not clear previous cookies, use SetCookie instead to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked response body.
Use Add for setting multiple header values under the same key.
func (*ResponseHeader) SetBytesK ¶
func (h *ResponseHeader) SetBytesK(key []byte, value string)
SetBytesK sets the given 'key: value' header.
Please note that the Set-Cookie header will not clear previous cookies, use SetCookie instead to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked response body.
Use AddBytesK for setting multiple header values under the same key.
func (*ResponseHeader) SetBytesKV ¶
func (h *ResponseHeader) SetBytesKV(key, value []byte)
SetBytesKV sets the given 'key: value' header.
Please note that the Set-Cookie header will not clear previous cookies, use SetCookie instead to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked response body.
Use AddBytesKV for setting multiple header values under the same key.
func (*ResponseHeader) SetBytesV ¶
func (h *ResponseHeader) SetBytesV(key string, value []byte)
SetBytesV sets the given 'key: value' header.
Please note that the Set-Cookie header will not clear previous cookies, use SetCookie instead to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked response body.
Use AddBytesV for setting multiple header values under the same key.
func (*ResponseHeader) SetCanonical ¶
func (h *ResponseHeader) SetCanonical(key, value []byte)
SetCanonical sets the given 'key: value' header assuming that key is in canonical form.
Please note that the Set-Cookie header will not clear previous cookies, use SetCookie instead to reset cookies.
If the header is set as a Trailer (forbidden trailers will not be set, see SetTrailer for more details), it will be sent after the chunked response body.
func (*ResponseHeader) SetConnectionClose ¶
func (h *ResponseHeader) SetConnectionClose()
SetConnectionClose sets 'Connection: close' header.
func (*ResponseHeader) SetContentEncoding ¶
func (h *ResponseHeader) SetContentEncoding(contentEncoding string)
SetContentEncoding sets Content-Encoding header value.
func (*ResponseHeader) SetContentEncodingBytes ¶
func (h *ResponseHeader) SetContentEncodingBytes(contentEncoding []byte)
SetContentEncodingBytes sets Content-Encoding header value.
func (*ResponseHeader) SetContentLength ¶
func (h *ResponseHeader) SetContentLength(contentLength int)
SetContentLength sets Content-Length header value.
Content-Length may be negative: -1 means Transfer-Encoding: chunked. -2 means Transfer-Encoding: identity.
func (*ResponseHeader) SetContentRange ¶
func (h *ResponseHeader) SetContentRange(startPos, endPos, contentLength int)
SetContentRange sets 'Content-Range: bytes startPos-endPos/contentLength' header.
func (*ResponseHeader) SetContentType ¶
func (h *ResponseHeader) SetContentType(contentType string)
SetContentType sets Content-Type header value.
func (*ResponseHeader) SetContentTypeBytes ¶
func (h *ResponseHeader) SetContentTypeBytes(contentType []byte)
SetContentTypeBytes sets Content-Type header value.
func (*ResponseHeader) SetCookie ¶
func (h *ResponseHeader) SetCookie(cookie *Cookie)
SetCookie sets the given response cookie.
It is safe re-using the cookie after the function returns.
func (*ResponseHeader) SetLastModified ¶
func (h *ResponseHeader) SetLastModified(t time.Time)
SetLastModified sets 'Last-Modified' header to the given value.
func (*ResponseHeader) SetNoDefaultContentType ¶
func (h *ResponseHeader) SetNoDefaultContentType(noDefaultContentType bool)
SetNoDefaultContentType allows you to control if a default Content-Type header will be set (false) or not (true).
func (*ResponseHeader) SetNonSpecial ¶
func (h *ResponseHeader) SetNonSpecial(key, value []byte)
SetNonSpecial directly put into map i.e. not a basic header.
func (*ResponseHeader) SetProtocol ¶
func (h *ResponseHeader) SetProtocol(protocol []byte)
SetProtocol sets response protocol bytes.
func (*ResponseHeader) SetServer ¶
func (h *ResponseHeader) SetServer(server string)
SetServer sets Server header value.
func (*ResponseHeader) SetServerBytes ¶
func (h *ResponseHeader) SetServerBytes(server []byte)
SetServerBytes sets Server header value.
func (*ResponseHeader) SetStatusCode ¶
func (h *ResponseHeader) SetStatusCode(statusCode int)
SetStatusCode sets response status code.
func (*ResponseHeader) SetStatusMessage ¶
func (h *ResponseHeader) SetStatusMessage(statusMessage []byte)
SetStatusMessage sets response status message bytes.
func (*ResponseHeader) SetTrailer ¶
SetTrailer sets header Trailer value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*ResponseHeader) SetTrailerBytes ¶
SetTrailerBytes sets Trailer header value for chunked response to indicate which headers will be sent after the body.
Use Set to set the trailer header later.
Trailers are only supported with chunked transfer. Trailers allow the sender to include additional headers at the end of chunked messages.
The following trailers are forbidden: 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length), 2. routing (e.g., Host), 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]), 4. authentication (e.g., see [RFC7235] and [RFC6265]), 5. response control data (e.g., see Section 7.1 of [RFC7231]), 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
Return ErrBadTrailer if contain any forbidden trailers.
func (*ResponseHeader) StatusCode ¶
func (h *ResponseHeader) StatusCode() int
StatusCode returns response status code.
func (*ResponseHeader) StatusMessage ¶
func (h *ResponseHeader) StatusMessage() []byte
StatusMessage returns response status message.
func (*ResponseHeader) String ¶
func (h *ResponseHeader) String() string
String returns response header representation.
func (*ResponseHeader) TrailerHeader ¶
func (h *ResponseHeader) TrailerHeader() []byte
TrailerHeader returns response trailer header representation.
Trailers will only be received with chunked transfer.
The returned value is valid until the request is released, either though ReleaseRequest or your request handler returning. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) Trailers ¶
Trailers returns an iterator over trailers in h.
The value of trailer may invalid outside the iteration loop.
func (*ResponseHeader) VisitAll
deprecated
func (h *ResponseHeader) VisitAll(f func(key, value []byte))
VisitAll calls f for each header.
f must not retain references to key and/or value after returning. Copy key and/or value contents before returning if you need retaining them.
Deprecated: Use All instead.
func (*ResponseHeader) VisitAllCookie
deprecated
func (h *ResponseHeader) VisitAllCookie(f func(key, value []byte))
VisitAllCookie calls f for each response cookie.
Cookie name is passed in key and the whole Set-Cookie header value is passed in value on each f invocation. Value may be parsed with Cookie.ParseBytes().
f must not retain references to key and/or value after returning.
Deprecated: Use Cookies instead.
func (*ResponseHeader) VisitAllTrailer
deprecated
func (h *ResponseHeader) VisitAllTrailer(f func(value []byte))
VisitAllTrailer calls f for each response Trailer.
f must not retain references to value after returning.
Deprecated: Use Trailers instead.
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup represents a group of routes.
func (*RouteGroup) Any ¶
func (g *RouteGroup) Any(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
Any adds route for all HTTP methods to group.
func (*RouteGroup) DELETE ¶
func (g *RouteGroup) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
DELETE adds DELETE route to group.
func (*RouteGroup) GET ¶
func (g *RouteGroup) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
GET adds GET route to group.
func (*RouteGroup) Group ¶
func (g *RouteGroup) Group(prefix string, middlewares ...MiddlewareFunc) *RouteGroup
Group creates a sub route group.
func (*RouteGroup) HEAD ¶
func (g *RouteGroup) HEAD(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
HEAD adds HEAD route to group.
func (*RouteGroup) OPTIONS ¶
func (g *RouteGroup) OPTIONS(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
OPTIONS adds OPTIONS route to group.
func (*RouteGroup) PATCH ¶
func (g *RouteGroup) PATCH(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
PATCH adds PATCH route to group.
func (*RouteGroup) POST ¶
func (g *RouteGroup) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
POST adds POST route to group.
func (*RouteGroup) PUT ¶
func (g *RouteGroup) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
PUT adds PUT route to group.
func (*RouteGroup) Use ¶
func (g *RouteGroup) Use(middlewares ...MiddlewareFunc)
Use adds middleware to route group.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router represents HTTP router using Gin's radix tree algorithm.
func (*Router) Any ¶
func (r *Router) Any(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
Any adds route for all HTTP methods.
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
DELETE adds DELETE route.
func (*Router) GET ¶
func (r *Router) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
GET adds GET route.
func (*Router) Group ¶
func (r *Router) Group(prefix string, middlewares ...MiddlewareFunc) *RouteGroup
Group creates a route group.
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
HEAD adds HEAD route.
func (*Router) NotFound ¶
func (r *Router) NotFound(handler HandlerFunc)
NotFound sets not found handler.
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
OPTIONS adds OPTIONS route.
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
PATCH adds PATCH route.
func (*Router) POST ¶
func (r *Router) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
POST adds POST route.
func (*Router) PUT ¶
func (r *Router) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
PUT adds PUT route.
func (*Router) Use ¶
func (r *Router) Use(middlewares ...MiddlewareFunc)
Use adds middleware to router.
type StreamWriter ¶
StreamWriter must write data to w.
Usually StreamWriter writes data to w in a loop (aka 'data streaming').
StreamWriter must return immediately if w returns error.
Since the written data is buffered, do not forget calling w.Flush when the data must be propagated to reader.
type URI ¶
type URI struct {
// Path values are sent as-is without normalization.
//
// Disabled path normalization may be useful for proxying incoming requests
// to servers that are expecting paths to be forwarded as-is.
//
// By default path values are normalized, i.e.
// extra slashes are removed, special characters are encoded.
DisablePathNormalizing bool
// contains filtered or unexported fields
}
URI represents URI :) .
It is forbidden copying URI instances. Create new instance and use CopyTo instead.
URI instance MUST NOT be used from concurrently running goroutines.
func AcquireURI ¶
func AcquireURI() *URI
AcquireURI returns an empty URI instance from the pool.
Release the URI with ReleaseURI after the URI is no longer needed. This allows reducing GC load.
func (*URI) AppendBytes ¶
AppendBytes appends full uri to dst and returns the extended dst.
func (*URI) FullURI ¶
FullURI returns full uri in the form {Scheme}://{Host}{RequestURI}#{Hash}.
The returned bytes are valid until the next URI method call.
func (*URI) Hash ¶
Hash returns URI hash, i.e. qwe of http://aaa.com/foo/bar?baz=123#qwe .
The returned bytes are valid until the next URI method call.
func (*URI) Host ¶
Host returns host part, i.e. aaa.com of http://aaa.com/foo/bar?baz=123#qwe .
Host is always lowercased.
The returned bytes are valid until the next URI method call.
func (*URI) LastPathSegment ¶
LastPathSegment returns the last part of uri path after '/'.
Examples:
- For /foo/bar/baz.html path returns baz.html.
- For /foo/bar/ returns empty byte slice.
- For /foobar.js returns foobar.js.
The returned bytes are valid until the next URI method call.
func (*URI) Parse ¶
Parse initializes URI from the given host and uri.
host may be nil. In this case uri must contain fully qualified uri, i.e. with scheme and host. http is assumed if scheme is omitted.
uri may contain e.g. RequestURI without scheme and host if host is non-empty.
func (*URI) Password ¶
Password returns URI password.
The returned bytes are valid until the next URI method call.
func (*URI) Path ¶
Path returns URI path, i.e. /foo/bar of http://aaa.com/foo/bar?baz=123#qwe .
The returned path is always urldecoded and normalized, i.e. '//f%20obar/baz/../zzz' becomes '/f obar/zzz'.
The returned bytes are valid until the next URI method call.
func (*URI) PathOriginal ¶
PathOriginal returns the original path from requestURI passed to URI.Parse().
The returned bytes are valid until the next URI method call.
func (*URI) QueryArgs ¶
QueryArgs returns query args.
The returned args are valid until the next URI method call.
func (*URI) QueryString ¶
QueryString returns URI query string, i.e. baz=123 of http://aaa.com/foo/bar?baz=123#qwe .
The returned bytes are valid until the next URI method call.
func (*URI) RequestURI ¶
RequestURI returns RequestURI - i.e. URI without Scheme and Host.
func (*URI) Scheme ¶
Scheme returns URI scheme, i.e. http of http://aaa.com/foo/bar?baz=123#qwe .
Returned scheme is always lowercased.
The returned bytes are valid until the next URI method call.
func (*URI) SetHostBytes ¶
SetHostBytes sets host for the uri.
func (*URI) SetPasswordBytes ¶
SetPasswordBytes sets URI password.
func (*URI) SetQueryString ¶
SetQueryString sets URI query string.
func (*URI) SetQueryStringBytes ¶
SetQueryStringBytes sets URI query string.
func (*URI) SetSchemeBytes ¶
SetSchemeBytes sets URI scheme, i.e. http, https, ftp, etc.
func (*URI) SetUsernameBytes ¶
SetUsernameBytes sets URI username.
func (*URI) Update ¶
Update updates uri.
The following newURI types are accepted:
- Absolute, i.e. http://foobar.com/aaa/bb?cc . In this case the original uri is replaced by newURI.
- Absolute without scheme, i.e. //foobar.com/aaa/bb?cc. In this case the original scheme is preserved.
- Missing host, i.e. /aaa/bb?cc . In this case only RequestURI part of the original uri is replaced.
- Relative path, i.e. xx?yy=abc . In this case the original RequestURI is updated according to the new relative path.
func (*URI) UpdateBytes ¶
UpdateBytes updates uri.
The following newURI types are accepted:
- Absolute, i.e. http://foobar.com/aaa/bb?cc . In this case the original uri is replaced by newURI.
- Absolute without scheme, i.e. //foobar.com/aaa/bb?cc. In this case the original scheme is preserved.
- Missing host, i.e. /aaa/bb?cc . In this case only RequestURI part of the original uri is replaced.
- Relative path, i.e. xx?yy=abc . In this case the original RequestURI is updated according to the new relative path.
type Writer ¶
type Writer interface {
Write(p []byte) (int, error)
Flush() error
Close() error
Reset(w io.Writer)
}
Writer is an interface stackless writer must conform to.
The interface contains common subset for Writers from compress/* packages.
func NewWriter ¶
func NewWriter(dstW io.Writer, newWriter NewWriterFunc) Writer
NewWriter creates a stackless writer around a writer returned from newWriter.
The returned writer writes data to dstW.
Writers that use a lot of stack space may be wrapped into stackless writer, thus saving stack space for high number of concurrently running goroutines.