Documentation ¶
Index ¶
- Constants
- Variables
- func AddFile(w *multipart.Writer, fieldName, path string) error
- func AddMultipartFormField(w *multipart.Writer, mf *MultipartField) error
- func CreateMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader
- func IsBadTrailer(key []byte) bool
- func MarshalMultipartForm(f *multipart.Form, boundary string) ([]byte, error)
- func ParseContentLength(b []byte) (int, error)
- func ParseMultipartForm(r io.Reader, request *Request, size, maxInMemoryFileSize int) error
- func ReadMultipartForm(r io.Reader, boundary string, size, maxInMemoryFileSize int) (*multipart.Form, error)
- func ReleaseCookie(c *Cookie)
- func ReleaseRequest(req *Request)
- func ReleaseResponse(resp *Response)
- func ReleaseURI(u *URI)
- func SetMultipartFormWithBoundary(req *Request, m *multipart.Form, boundary string)
- func SwapRequestBody(a, b *Request)
- func SwapResponseBody(a, b *Response)
- func UpdateServerDate()
- func WriteMultipartForm(w io.Writer, f *multipart.Form, boundary string) error
- func WriteMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r io.Reader) error
- type Args
- func (a *Args) Add(key, value string)
- 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) Has(key string) bool
- func (a *Args) Len() int
- func (a *Args) ParseBytes(b []byte)
- func (a *Args) Peek(key string) []byte
- func (a *Args) PeekAll(key string) [][]byte
- func (a *Args) PeekExists(key string) (string, bool)
- func (a *Args) QueryString() []byte
- func (a *Args) Reset()
- func (a *Args) Set(key, value string)
- func (a *Args) String() string
- func (a *Args) VisitAll(f func(key, value []byte))
- func (a *Args) WriteTo(w io.Writer) (int64, error)
- type Cookie
- func (c *Cookie) AppendBytes(dst []byte) []byte
- func (c *Cookie) Cookie() []byte
- 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) 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
- type CookieSameSite
- type File
- type MultipartField
- type Proxy
- type Request
- func (req *Request) AppendBody(p []byte)
- func (req *Request) AppendBodyString(s string)
- func (req *Request) BasicAuth() (username, password string, ok bool)
- func (req *Request) Body() []byte
- func (req *Request) BodyBuffer() *bytebufferpool.ByteBuffer
- func (req *Request) BodyBytes() []byte
- func (req *Request) BodyE() ([]byte, error)
- func (req *Request) BodyStream() io.Reader
- func (req *Request) BodyWriteTo(w io.Writer) error
- func (req *Request) BodyWriter() io.Writer
- func (req *Request) CloseBodyStream() error
- func (req *Request) ConnectionClose() bool
- func (req *Request) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)
- func (req *Request) CopyTo(dst *Request)
- func (req *Request) CopyToSkipBody(dst *Request)
- func (req *Request) FormFile(name string) (*multipart.FileHeader, error)
- func (req *Request) HasMultipartForm() bool
- func (req *Request) Host() []byte
- func (req *Request) IsBodyStream() bool
- func (req *Request) IsURIParsed() bool
- func (req *Request) MayContinue() bool
- func (req *Request) Method() []byte
- func (req *Request) MultipartFields() []*MultipartField
- func (req *Request) MultipartFiles() []*File
- func (req *Request) MultipartForm() (*multipart.Form, error)
- func (req *Request) MultipartFormBoundary() string
- func (req *Request) OnlyMultipartForm() bool
- func (req *Request) Options() *config.RequestOptions
- func (req *Request) ParseURI()
- func (req *Request) Path() []byte
- func (req *Request) PostArgString() []byte
- func (req *Request) PostArgs() *Args
- func (req *Request) QueryString() []byte
- func (req *Request) RemoveMultipartFormFiles()
- func (req *Request) RequestURI() []byte
- func (req *Request) Reset()
- func (req *Request) ResetBody()
- func (req *Request) ResetSkipHeader()
- func (req *Request) ResetWithoutConn()
- func (req *Request) Scheme() []byte
- func (req *Request) SetAuthSchemeToken(scheme, token string)
- func (req *Request) SetAuthToken(token string)
- func (req *Request) SetBasicAuth(username, password string)
- func (req *Request) SetBody(body []byte)
- func (req *Request) SetBodyRaw(body []byte)
- func (req *Request) SetBodyStream(bodyStream io.Reader, bodySize int)
- func (req *Request) SetBodyString(body string)
- func (req *Request) SetConnectionClose()
- func (req *Request) SetCookie(key, value string)
- func (req *Request) SetCookies(hc map[string]string)
- func (req *Request) SetFile(param, filePath string)
- func (req *Request) SetFileReader(param, fileName string, reader io.Reader)
- func (req *Request) SetFiles(files map[string]string)
- func (req *Request) SetFormData(data map[string]string)
- func (req *Request) SetFormDataFromValues(data url.Values)
- func (req *Request) SetHeader(header, value string)
- func (req *Request) SetHeaders(headers map[string]string)
- func (req *Request) SetHost(host string)
- func (req *Request) SetIsTLS(isTLS bool)
- func (req *Request) SetMaxKeepBodySize(n int)
- func (req *Request) SetMethod(method string)
- func (req *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader)
- func (req *Request) SetMultipartFields(fields ...*MultipartField)
- func (req *Request) SetMultipartFormBoundary(b string)
- func (req *Request) SetMultipartFormData(data map[string]string)
- func (req *Request) SetOptions(opts ...config.RequestOption)
- func (req *Request) SetQueryString(queryString string)
- func (req *Request) SetRequestURI(requestURI string)
- func (req *Request) SwapBody(body []byte) []byte
- func (req *Request) URI() *URI
- type RequestHeader
- func (h *RequestHeader) Add(key, value string)
- func (h *RequestHeader) AddArgBytes(key, value []byte, noValue bool)
- func (h *RequestHeader) AppendBytes(dst []byte) []byte
- func (h *RequestHeader) ConnectionClose() bool
- func (h *RequestHeader) ContentLength() int
- func (h *RequestHeader) ContentLengthBytes() []byte
- func (h *RequestHeader) ContentType() []byte
- func (h *RequestHeader) Cookie(key string) []byte
- func (h *RequestHeader) Cookies() []*Cookie
- 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) DisableNormalizing()
- func (h *RequestHeader) FullCookie() []byte
- func (h *RequestHeader) Get(key string) string
- func (h *RequestHeader) GetAll(key string) []string
- func (h *RequestHeader) GetBufValue() []byte
- func (h *RequestHeader) GetProtocol() string
- func (h *RequestHeader) HasAcceptEncodingBytes(acceptEncoding []byte) bool
- func (h *RequestHeader) Header() []byte
- func (h *RequestHeader) Host() []byte
- func (h *RequestHeader) IgnoreBody() bool
- func (h *RequestHeader) InitBufValue(size int)
- func (h *RequestHeader) InitContentLengthWithValue(contentLength int)
- func (h *RequestHeader) IsConnect() bool
- func (h *RequestHeader) IsDelete() bool
- func (h *RequestHeader) IsDisableNormalizing() bool
- func (h *RequestHeader) IsGet() bool
- func (h *RequestHeader) IsHTTP11() bool
- func (h *RequestHeader) IsHead() bool
- func (h *RequestHeader) IsOptions() 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) PeekArgBytes(key []byte) []byte
- func (h *RequestHeader) PeekContentEncoding() []byte
- func (h *RequestHeader) PeekIfModifiedSinceBytes() []byte
- func (h *RequestHeader) PeekRange() []byte
- func (h *RequestHeader) RawHeaders() []byte
- func (h *RequestHeader) RequestURI() []byte
- func (h *RequestHeader) Reset()
- func (h *RequestHeader) ResetConnectionClose()
- func (h *RequestHeader) ResetSkipNormalize()
- func (h *RequestHeader) Set(key, value string)
- func (h *RequestHeader) SetArgBytes(key, value []byte, noValue bool)
- func (h *RequestHeader) SetByteRange(startPos, endPos int)
- func (h *RequestHeader) SetBytesKV(key, value []byte)
- func (h *RequestHeader) SetCanonical(key, value []byte)
- func (h *RequestHeader) SetConnectionClose(close bool)
- func (h *RequestHeader) SetContentLength(contentLength int)
- func (h *RequestHeader) SetContentLengthBytes(contentLength []byte)
- func (h *RequestHeader) SetContentTypeBytes(contentType []byte)
- func (h *RequestHeader) SetCookie(key, value string)
- 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) SetNoDefaultContentType(b bool)
- func (h *RequestHeader) SetNoHTTP11(b bool)deprecated
- func (h *RequestHeader) SetProtocol(p string)
- func (h *RequestHeader) SetRawHeaders(r []byte)
- func (h *RequestHeader) SetRequestURI(requestURI string)
- func (h *RequestHeader) SetRequestURIBytes(requestURI []byte)
- func (h *RequestHeader) SetUserAgentBytes(userAgent []byte)
- func (h *RequestHeader) String() string
- func (h *RequestHeader) Trailer() *Trailer
- func (h *RequestHeader) UserAgent() []byte
- func (h *RequestHeader) VisitAll(f func(key, value []byte))
- func (h *RequestHeader) VisitAllCookie(f func(key, value []byte))
- func (h *RequestHeader) VisitAllCustomHeader(f func(key, value []byte))
- type Response
- func (resp *Response) AppendBody(p []byte)
- func (resp *Response) AppendBodyString(s string)
- func (resp *Response) Body() []byte
- func (resp *Response) BodyBuffer() *bytebufferpool.ByteBuffer
- func (resp *Response) BodyBytes() []byte
- func (resp *Response) BodyE() ([]byte, error)
- func (resp *Response) BodyGunzip() ([]byte, error)
- func (resp *Response) BodyStream() io.Reader
- func (resp *Response) BodyWriteTo(w io.Writer) error
- func (resp *Response) BodyWriter() io.Writer
- func (resp *Response) CloseBodyStream() error
- func (resp *Response) ConnectionClose() bool
- func (resp *Response) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)
- func (resp *Response) CopyTo(dst *Response)
- func (resp *Response) CopyToSkipBody(dst *Response)
- func (resp *Response) GetHijackWriter() network.ExtWriter
- func (resp *Response) HasBodyBytes() bool
- func (resp *Response) HijackWriter(writer network.ExtWriter)
- func (resp *Response) IsBodyStream() bool
- func (resp *Response) LocalAddr() net.Addr
- func (resp *Response) MustSkipBody() bool
- func (resp *Response) ParseNetAddr(conn network.Conn)
- func (resp *Response) RemoteAddr() net.Addr
- func (resp *Response) Reset()
- func (resp *Response) ResetBody()
- func (resp *Response) SetBody(body []byte)
- func (resp *Response) SetBodyRaw(body []byte)
- func (resp *Response) SetBodyStream(bodyStream io.Reader, bodySize int)
- func (resp *Response) SetBodyStreamNoReset(bodyStream io.Reader, bodySize int)
- func (resp *Response) SetBodyString(body string)
- func (resp *Response) SetConnectionClose()
- func (resp *Response) SetMaxKeepBodySize(n int)
- func (resp *Response) SetStatusCode(statusCode int)
- func (resp *Response) StatusCode() int
- type ResponseHeader
- func (h *ResponseHeader) Add(key, value string)
- func (h *ResponseHeader) AddArgBytes(key, value []byte, noValue bool)
- func (h *ResponseHeader) AppendBytes(dst []byte) []byte
- func (h *ResponseHeader) ConnectionClose() bool
- func (h *ResponseHeader) ContentEncoding() []byte
- func (h *ResponseHeader) ContentLength() int
- func (h *ResponseHeader) ContentLengthBytes() []byte
- func (h *ResponseHeader) ContentType() []byte
- func (h *ResponseHeader) Cookie(cookie *Cookie) bool
- 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) FullCookie() []byte
- func (h *ResponseHeader) Get(key string) string
- func (h *ResponseHeader) GetAll(key string) []string
- func (h *ResponseHeader) GetCookies() []argsKV
- func (h *ResponseHeader) GetHeaderLength() int
- func (h *ResponseHeader) GetHeaders() []argsKV
- func (h *ResponseHeader) GetProtocol() string
- func (h *ResponseHeader) Header() []byte
- func (h *ResponseHeader) InitContentLengthWithValue(contentLength int)
- func (h *ResponseHeader) IsDisableNormalizing() bool
- func (h *ResponseHeader) IsHTTP11() bool
- func (h *ResponseHeader) Len() int
- func (h *ResponseHeader) MustSkipContentLength() bool
- func (h *ResponseHeader) NoDefaultContentType() bool
- func (h *ResponseHeader) ParseSetCookie(value []byte)
- func (h *ResponseHeader) Peek(key string) []byte
- func (h *ResponseHeader) PeekAll(key string) [][]byte
- func (h *ResponseHeader) PeekArgBytes(key []byte) []byte
- func (h *ResponseHeader) PeekLocation() []byte
- func (h *ResponseHeader) Reset()
- func (h *ResponseHeader) ResetConnectionClose()
- func (h *ResponseHeader) ResetSkipNormalize()
- func (h *ResponseHeader) Server() []byte
- func (h *ResponseHeader) Set(key, value string)
- func (h *ResponseHeader) SetArgBytes(key, value []byte, noValue bool)
- func (h *ResponseHeader) SetBytesV(key string, value []byte)
- func (h *ResponseHeader) SetCanonical(key, value []byte)
- func (h *ResponseHeader) SetConnectionClose(close bool)
- func (h *ResponseHeader) SetContentEncoding(contentEncoding string)
- func (h *ResponseHeader) SetContentEncodingBytes(contentEncoding []byte)
- func (h *ResponseHeader) SetContentLength(contentLength int)
- func (h *ResponseHeader) SetContentLengthBytes(contentLength []byte)
- 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) SetHeaderLength(length int)
- func (h *ResponseHeader) SetNoDefaultContentType(b bool)
- func (h *ResponseHeader) SetNoDefaultDate(b bool)
- func (h *ResponseHeader) SetNoHTTP11(b bool)deprecated
- func (h *ResponseHeader) SetProtocol(p string)
- func (h *ResponseHeader) SetServerBytes(server []byte)
- func (h *ResponseHeader) SetStatusCode(statusCode int)
- func (h *ResponseHeader) StatusCode() int
- func (h *ResponseHeader) Trailer() *Trailer
- func (h *ResponseHeader) VisitAll(f func(key, value []byte))
- func (h *ResponseHeader) VisitAllCookie(f func(key, value []byte))
- type Server
- type StreamServer
- type Trailer
- func (t *Trailer) Add(key, value string) error
- func (t *Trailer) AppendBytes(dst []byte) []byte
- func (t *Trailer) CopyTo(dst *Trailer)
- func (t *Trailer) Del(key string)
- func (t *Trailer) DisableNormalizing()
- func (t *Trailer) Empty() bool
- func (t *Trailer) Get(key string) string
- func (t *Trailer) GetBytes() []byte
- func (t *Trailer) GetTrailers() []argsKV
- func (t *Trailer) Header() []byte
- func (t *Trailer) IsDisableNormalizing() bool
- func (t *Trailer) Peek(key string) []byte
- func (t *Trailer) Reset()
- func (t *Trailer) ResetSkipNormalize()
- func (t *Trailer) Set(key, value string) error
- func (t *Trailer) SetTrailers(trailers []byte) (err error)
- func (t *Trailer) UpdateArgBytes(key, value []byte) error
- func (t *Trailer) VisitAll(f func(key, value []byte))
- 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)
- 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
Constants ¶
const (
ArgsHasValue = false
)
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 ( ServerDate atomic.Value ServerDateOnce sync.Once // serverDateOnce.Do(updateServerDate) )
var (
ErrMissingFile = errors.NewPublic("http: no such file")
)
var NoBody = noBody{}
NoBody is an io.ReadCloser with no bytes. Read always returns EOF and Close always returns nil. It can be used in an outgoing client request to explicitly signal that a request has zero bytes.
var ( // NoResponseBody is an io.ReadCloser with no bytes. Read always returns EOF // and Close always returns nil. It can be used in an ingoing client // response to explicitly signal that a response has zero bytes. NoResponseBody = noBody{} )
Functions ¶
func AddMultipartFormField ¶
func AddMultipartFormField(w *multipart.Writer, mf *MultipartField) error
func CreateMultipartHeader ¶
func CreateMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader
func IsBadTrailer ¶ added in v0.6.0
func MarshalMultipartForm ¶
func ParseContentLength ¶
func ParseMultipartForm ¶
func ReadMultipartForm ¶
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.
It is forbidden accessing req and/or its members after returning it to request pool.
func ReleaseResponse ¶
func ReleaseResponse(resp *Response)
ReleaseResponse return resp acquired via AcquireResponse to response pool.
It is forbidden accessing resp and/or its members after returning it to response pool.
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 SwapRequestBody ¶
func SwapRequestBody(a, b *Request)
func SwapResponseBody ¶
func SwapResponseBody(a, b *Response)
func UpdateServerDate ¶
func UpdateServerDate()
func WriteMultipartForm ¶
WriteMultipartForm writes the given multipart form f with the given boundary to w.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
func (*Args) AppendBytes ¶
AppendBytes appends query string to dst and returns the extended dst.
func (*Args) ParseBytes ¶
ParseBytes parses the given b containing query args.
func (*Args) Peek ¶
Peek returns query arg value for the given key.
Returned value is valid until the next Args call.
func (*Args) QueryString ¶
QueryString returns query string for the args.
The returned value is valid until the next call to Args methods.
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 next call to Cookie methods.
func (*Cookie) Domain ¶
Domain returns cookie domain.
The returned domain is valid until the next Cookie modification method call.
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 next Cookie modification method call.
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 ¶ added in v0.8.0
Partitioned returns if cookie is partitioned.
func (*Cookie) SameSite ¶
func (c *Cookie) SameSite() CookieSameSite
SameSite returns the SameSite mode.
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
Set max age to 0 to unset
func (*Cookie) SetPartitioned ¶ added in v0.8.0
SetPartitioned sets cookie as partitioned. Setting Partitioned to true will also set Secure.
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 // third-party cookies are phasing out, use Partitioned cookies instead // see https://developers.google.com/privacy-sandbox/3pcd CookieSameSiteNoneMode )
type MultipartField ¶
MultipartField struct represent custom data part for multipart request
type Request ¶
type Request struct { Header RequestHeader // contains filtered or unexported fields }
func AcquireRequest ¶
func AcquireRequest() *Request
AcquireRequest returns an empty Request instance from request pool.
The returned Request instance may be passed to ReleaseRequest when it is no longer needed. This allows Request recycling, reduces GC pressure and usually improves performance.
func NewRequest ¶
NewRequest makes a new Request given a method, URL, and optional body.
Method's default value is GET ¶
Url must contain fully qualified uri, i.e. with scheme and host, and http is assumed if scheme is omitted.
Protocol version is always HTTP/1.1
NewRequest just uses for unit-testing. Use AcquireRequest() in other cases.
func (*Request) AppendBody ¶
AppendBody appends p to request body.
It is safe re-using p after the function returns.
func (*Request) AppendBodyString ¶
AppendBodyString appends s to request body.
func (*Request) BasicAuth ¶
BasicAuth can return the username and password in the request's Authorization header, if the request uses the HTTP Basic Authorization.
func (*Request) BodyBuffer ¶
func (req *Request) BodyBuffer() *bytebufferpool.ByteBuffer
func (*Request) BodyStream ¶
func (*Request) BodyWriteTo ¶
BodyWriteTo writes request body to w.
func (*Request) BodyWriter ¶
BodyWriter returns writer for populating request body.
func (*Request) CloseBodyStream ¶
func (*Request) ConnectionClose ¶
ConnectionClose returns true if 'Connection: close' header is set.
func (*Request) ConstructBodyStream ¶
func (req *Request) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)
func (*Request) CopyToSkipBody ¶
func (*Request) FormFile ¶
func (req *Request) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the first file for the provided form key.
func (*Request) HasMultipartForm ¶
func (*Request) IsBodyStream ¶
IsBodyStream returns true if body is set via SetBodyStream*
func (*Request) IsURIParsed ¶
func (*Request) MayContinue ¶
MayContinue returns true if the request contains 'Expect: 100-continue' header.
The caller must do one of the following actions if MayContinue returns true:
- Either send StatusExpectationFailed response if request headers don't satisfy the caller.
- Or send StatusContinue response before reading request body with ContinueReadBody.
- Or close the connection.
func (*Request) MultipartFields ¶
func (req *Request) MultipartFields() []*MultipartField
func (*Request) MultipartFiles ¶
func (*Request) MultipartForm ¶
MultipartForm returns request's multipart form.
Returns errors.ErrNoMultipartForm if request's Content-Type isn't 'multipart/form-data'.
RemoveMultipartFormFiles must be called after returned multipart form is processed.
func (*Request) MultipartFormBoundary ¶
func (*Request) OnlyMultipartForm ¶
func (*Request) Options ¶
func (req *Request) Options() *config.RequestOptions
func (*Request) PostArgString ¶
func (*Request) QueryString ¶
QueryString returns request query
func (*Request) RemoveMultipartFormFiles ¶
func (req *Request) RemoveMultipartFormFiles()
RemoveMultipartFormFiles removes multipart/form-data temporary files associated with the request.
func (*Request) RequestURI ¶
RequestURI returns the RequestURI for the given request.
func (*Request) ResetSkipHeader ¶
func (req *Request) ResetSkipHeader()
func (*Request) ResetWithoutConn ¶ added in v0.6.7
func (req *Request) ResetWithoutConn()
func (*Request) Scheme ¶
Scheme returns the scheme of the request. uri will be parsed in ServeHTTP(before user's process), so that there is no need for uri nil-check.
func (*Request) SetAuthSchemeToken ¶
SetAuthSchemeToken sets the auth token scheme type in the HTTP request. For Example:
Authorization: <auth-scheme-value-set-here> <auth-token-value>
func (*Request) SetAuthToken ¶
SetAuthToken sets the auth token header(Default Scheme: Bearer) in the current HTTP request. Header example:
Authorization: Bearer <auth-token-value-comes-here>
func (*Request) SetBasicAuth ¶
SetBasicAuth sets the basic authentication header in the current HTTP request.
func (*Request) SetBody ¶
SetBody sets request body.
It is safe re-using body argument after the function returns.
func (*Request) SetBodyRaw ¶
SetBodyRaw sets request body, but without copying it.
From this point onward the body argument must not be changed.
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.
Note that GET and HEAD requests cannot have body.
See also SetBodyStreamWriter.
func (*Request) SetBodyString ¶
SetBodyString sets request body.
func (*Request) SetConnectionClose ¶
func (req *Request) SetConnectionClose()
SetConnectionClose sets 'Connection: close' header.
func (*Request) SetCookies ¶
SetCookies sets an array of cookies in the current request instance.
func (*Request) SetFileReader ¶
SetFileReader sets single file using io.Reader for multipart upload.
func (*Request) SetFiles ¶
SetFiles sets multiple file field name and its path for multipart upload.
func (*Request) SetFormData ¶
SetFormData sets x-www-form-urlencoded params
func (*Request) SetFormDataFromValues ¶
SetFormDataFromValues sets x-www-form-urlencoded params from url values.
func (*Request) SetHeader ¶
SetHeader sets a single header field and its value in the current request.
func (*Request) SetHeaders ¶
SetHeaders sets multiple header field and its value in the current request.
func (*Request) SetIsTLS ¶
SetIsTLS is used by TLS server to mark whether the request is a TLS request. Client shouldn't use this method but should depend on the uri.scheme instead.
func (*Request) SetMaxKeepBodySize ¶
func (*Request) SetMultipartField ¶
SetMultipartField sets custom data using io.Reader for multipart upload.
func (*Request) SetMultipartFields ¶
func (req *Request) SetMultipartFields(fields ...*MultipartField)
SetMultipartFields sets multiple data fields using io.Reader for multipart upload.
func (*Request) SetMultipartFormBoundary ¶
SetMultipartFormBoundary will set the multipart form boundary for the request.
func (*Request) SetMultipartFormData ¶
SetMultipartFormData method allows simple form data to be attached to the request as `multipart:form-data`
func (*Request) SetOptions ¶
func (req *Request) SetOptions(opts ...config.RequestOption)
SetOptions is used to set request options. These options can be used to do something in middlewares such as service discovery.
func (*Request) SetQueryString ¶
SetQueryString sets query string.
func (*Request) SetRequestURI ¶
SetRequestURI sets RequestURI.
type RequestHeader ¶
type RequestHeader struct {
// contains filtered or unexported fields
}
func (*RequestHeader) Add ¶
func (h *RequestHeader) Add(key, value string)
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, Cookie, Transfer-Encoding, Host and User-Agent headers can only be set once and will overwrite the previous value.
func (*RequestHeader) AddArgBytes ¶
func (h *RequestHeader) AddArgBytes(key, value []byte, noValue bool)
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) ContentLength ¶
func (h *RequestHeader) ContentLength() int
ContentLength returns Content-Length header value.
It may be negative: -1 means Transfer-Encoding: chunked.
func (*RequestHeader) ContentLengthBytes ¶
func (h *RequestHeader) ContentLengthBytes() []byte
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) Cookies ¶ added in v0.5.1
func (h *RequestHeader) Cookies() []*Cookie
Cookies returns all the request cookies.
It's a good idea to call protocol.ReleaseCookie to reduce GC load after the cookie used.
func (*RequestHeader) CopyTo ¶
func (h *RequestHeader) CopyTo(dst *RequestHeader)
CopyTo copies all the headers to dst.
func (*RequestHeader) Del ¶ added in v0.7.0
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) 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 you know what are you doing.
func (*RequestHeader) FullCookie ¶
func (h *RequestHeader) FullCookie() []byte
FullCookie returns complete cookie bytes
func (*RequestHeader) Get ¶
func (h *RequestHeader) Get(key string) string
func (*RequestHeader) GetAll ¶ added in v0.5.2
func (h *RequestHeader) GetAll(key string) []string
GetAll returns all header value for the given key it is concurrent safety and long lifetime.
func (*RequestHeader) GetBufValue ¶
func (h *RequestHeader) GetBufValue() []byte
func (*RequestHeader) GetProtocol ¶
func (h *RequestHeader) GetProtocol() string
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.
The returned representation is valid until the next call to RequestHeader methods.
func (*RequestHeader) IgnoreBody ¶
func (h *RequestHeader) IgnoreBody() bool
func (*RequestHeader) InitBufValue ¶
func (h *RequestHeader) InitBufValue(size int)
func (*RequestHeader) InitContentLengthWithValue ¶
func (h *RequestHeader) InitContentLengthWithValue(contentLength int)
func (*RequestHeader) IsConnect ¶
func (h *RequestHeader) IsConnect() bool
IsConnect returns true if request method is CONNECT.
func (*RequestHeader) IsDelete ¶ added in v0.4.0
func (h *RequestHeader) IsDelete() bool
IsDelete returns true if request method is DELETE.
func (*RequestHeader) IsDisableNormalizing ¶
func (h *RequestHeader) IsDisableNormalizing() bool
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 request is HTTP/1.1.
func (*RequestHeader) IsHead ¶
func (h *RequestHeader) IsHead() bool
IsHead returns true if request method is HEAD.
func (*RequestHeader) IsOptions ¶ added in v0.4.0
func (h *RequestHeader) IsOptions() bool
IsOptions returns true if request method is Options.
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 ¶ added in v0.4.0
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.
Returned value is valid until the next call to RequestHeader. Do not store references to returned value. Make copies instead.
func (*RequestHeader) PeekAll ¶ added in v0.5.2
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. Use RequestHeader.GetAll(key) instead.
func (*RequestHeader) PeekArgBytes ¶
func (h *RequestHeader) PeekArgBytes(key []byte) []byte
func (*RequestHeader) PeekContentEncoding ¶
func (h *RequestHeader) PeekContentEncoding() []byte
func (*RequestHeader) PeekIfModifiedSinceBytes ¶
func (h *RequestHeader) PeekIfModifiedSinceBytes() []byte
func (*RequestHeader) PeekRange ¶
func (h *RequestHeader) PeekRange() []byte
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) 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) ResetSkipNormalize ¶
func (h *RequestHeader) ResetSkipNormalize()
func (*RequestHeader) Set ¶
func (h *RequestHeader) Set(key, value string)
Set sets the given 'key: value' header.
Use Add for setting multiple header values under the same key.
func (*RequestHeader) SetArgBytes ¶
func (h *RequestHeader) SetArgBytes(key, value []byte, noValue bool)
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) SetBytesKV ¶
func (h *RequestHeader) SetBytesKV(key, value []byte)
SetBytesKV sets the given 'key: value' header.
Use AddBytesKV 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.
func (*RequestHeader) SetConnectionClose ¶
func (h *RequestHeader) SetConnectionClose(close bool)
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) SetContentLengthBytes ¶
func (h *RequestHeader) SetContentLengthBytes(contentLength []byte)
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) 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) SetNoDefaultContentType ¶ added in v0.4.1
func (h *RequestHeader) SetNoDefaultContentType(b bool)
SetNoDefaultContentType controls the default Content-Type header behaviour.
When set to false, the Content-Type header is sent with a default value if no Content-Type value is specified. When set to true, no Content-Type header is sent if no Content-Type value is specified.
func (*RequestHeader) SetNoHTTP11
deprecated
func (h *RequestHeader) SetNoHTTP11(b bool)
Deprecated: Use RequestHeader.SetProtocol(consts.HTTP11) instead
Now SetNoHTTP11(true) equal to SetProtocol(consts.HTTP10) SetNoHTTP11(false) equal to SetProtocol(consts.HTTP11)
func (*RequestHeader) SetProtocol ¶
func (h *RequestHeader) SetProtocol(p string)
func (*RequestHeader) SetRawHeaders ¶
func (h *RequestHeader) SetRawHeaders(r []byte)
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) 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) Trailer ¶ added in v0.6.0
func (h *RequestHeader) Trailer() *Trailer
Trailer returns the Trailer of HTTP Header.
func (*RequestHeader) UserAgent ¶
func (h *RequestHeader) UserAgent() []byte
UserAgent returns User-Agent header value.
func (*RequestHeader) VisitAll ¶
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.
func (*RequestHeader) VisitAllCookie ¶
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.
func (*RequestHeader) VisitAllCustomHeader ¶ added in v0.1.0
func (h *RequestHeader) VisitAllCustomHeader(f func(key, value []byte))
VisitAllCustomHeader calls f for each header in header.h which contains all headers except cookie, host, content-length, content-type, user-agent and connection.
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.
type Response ¶
type Response struct { // Response header // // Copying Header by value is forbidden. Use pointer to Header instead. Header ResponseHeader // Flush headers as soon as possible without waiting for first body bytes. // Relevant for bodyStream only. ImmediateHeaderFlush bool // Response.Read() skips reading body if set to true. // Use it for reading HEAD responses. // // Response.Write() skips writing body if set to true. // Use it for writing HEAD responses. SkipBody bool // contains filtered or unexported fields }
Response represents HTTP response.
It is forbidden copying Response instances. Create new instances and use CopyTo instead.
Response instance MUST NOT be used from concurrently running goroutines.
func AcquireResponse ¶
func AcquireResponse() *Response
AcquireResponse returns an empty Response instance from response pool.
The returned Response instance may be passed to ReleaseResponse when it is no longer needed. This allows Response recycling, reduces GC pressure and usually improves performance.
func (*Response) AppendBody ¶
AppendBody appends p to response body.
It is safe re-using p after the function returns.
func (*Response) AppendBodyString ¶
AppendBodyString appends s to response body.
func (*Response) BodyBuffer ¶
func (resp *Response) BodyBuffer() *bytebufferpool.ByteBuffer
func (*Response) BodyGunzip ¶
BodyGunzip returns un-gzipped body data.
This method may be used if the response header contains 'Content-Encoding: gzip' for reading un-gzipped body. Use Body for reading gzipped response body.
func (*Response) BodyStream ¶
func (*Response) BodyWriteTo ¶
BodyWriteTo writes response body to w.
func (*Response) BodyWriter ¶
BodyWriter returns writer for populating response body.
If used inside RequestHandler, the returned writer must not be used after returning from RequestHandler. Use RequestContext.Write or SetBodyStreamWriter in this case.
func (*Response) CloseBodyStream ¶
func (*Response) ConnectionClose ¶
ConnectionClose returns true if 'Connection: close' header is set.
func (*Response) ConstructBodyStream ¶
func (resp *Response) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)
func (*Response) CopyToSkipBody ¶
func (*Response) GetHijackWriter ¶ added in v0.6.0
func (*Response) HasBodyBytes ¶
func (*Response) HijackWriter ¶ added in v0.6.0
func (*Response) IsBodyStream ¶
IsBodyStream returns true if body is set via SetBodyStream*
func (*Response) LocalAddr ¶
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*Response) MustSkipBody ¶
func (*Response) ParseNetAddr ¶
func (*Response) RemoteAddr ¶
RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
func (*Response) SetBody ¶
SetBody sets response body.
It is safe re-using body argument after the function returns.
func (*Response) SetBodyRaw ¶
SetBodyRaw sets response body, but without copying it.
From this point onward the body argument must not be changed.
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) SetBodyStreamNoReset ¶ added in v0.4.2
SetBodyStreamNoReset is almost the same as SetBodyStream, but it doesn't reset the bodyStream before.
func (*Response) SetBodyString ¶
SetBodyString sets response body.
func (*Response) SetConnectionClose ¶
func (resp *Response) SetConnectionClose()
SetConnectionClose sets 'Connection: close' header.
func (*Response) SetMaxKeepBodySize ¶
func (*Response) SetStatusCode ¶
SetStatusCode sets response status code.
func (*Response) StatusCode ¶
StatusCode returns response status code.
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, Set-Cookie, Transfer-Encoding and Date headers can only be set once and will overwrite the previous value.
func (*ResponseHeader) AddArgBytes ¶
func (h *ResponseHeader) AddArgBytes(key, value []byte, noValue bool)
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) ContentEncoding ¶ added in v0.5.0
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) ContentLengthBytes ¶
func (h *ResponseHeader) ContentLengthBytes() []byte
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) 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 you know what are you doing.
func (*ResponseHeader) FullCookie ¶
func (h *ResponseHeader) FullCookie() []byte
FullCookie returns complete cookie bytes
func (*ResponseHeader) Get ¶
func (h *ResponseHeader) Get(key string) string
func (*ResponseHeader) GetAll ¶ added in v0.5.2
func (h *ResponseHeader) GetAll(key string) []string
GetAll returns all header value for the given key and is concurrent safety. it is concurrent safety and long lifetime.
func (*ResponseHeader) GetCookies ¶
func (h *ResponseHeader) GetCookies() []argsKV
func (*ResponseHeader) GetHeaderLength ¶
func (h *ResponseHeader) GetHeaderLength() int
GetHeaderLength gets the size of header for tracer.
func (*ResponseHeader) GetHeaders ¶
func (h *ResponseHeader) GetHeaders() []argsKV
func (*ResponseHeader) GetProtocol ¶ added in v0.6.3
func (h *ResponseHeader) GetProtocol() string
func (*ResponseHeader) Header ¶
func (h *ResponseHeader) Header() []byte
Header returns response header representation.
The returned value is valid until the next call to ResponseHeader methods.
func (*ResponseHeader) InitContentLengthWithValue ¶
func (h *ResponseHeader) InitContentLengthWithValue(contentLength int)
func (*ResponseHeader) IsDisableNormalizing ¶
func (h *ResponseHeader) IsDisableNormalizing() bool
func (*ResponseHeader) IsHTTP11 ¶
func (h *ResponseHeader) IsHTTP11() bool
IsHTTP11 returns true if the response 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) MustSkipContentLength ¶
func (h *ResponseHeader) MustSkipContentLength() bool
func (*ResponseHeader) NoDefaultContentType ¶
func (h *ResponseHeader) NoDefaultContentType() bool
func (*ResponseHeader) ParseSetCookie ¶
func (h *ResponseHeader) ParseSetCookie(value []byte)
func (*ResponseHeader) Peek ¶
func (h *ResponseHeader) Peek(key string) []byte
Peek returns header value for the given key.
Returned value is valid until the next call to ResponseHeader. Do not store references to returned value. Make copies instead.
func (*ResponseHeader) PeekAll ¶ added in v0.5.2
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. Use ResponseHeader.GetAll(key) instead.
func (*ResponseHeader) PeekArgBytes ¶
func (h *ResponseHeader) PeekArgBytes(key []byte) []byte
func (*ResponseHeader) PeekLocation ¶
func (h *ResponseHeader) PeekLocation() []byte
func (*ResponseHeader) ResetConnectionClose ¶
func (h *ResponseHeader) ResetConnectionClose()
ResetConnectionClose clears 'Connection: close' header if it exists.
func (*ResponseHeader) ResetSkipNormalize ¶
func (h *ResponseHeader) ResetSkipNormalize()
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.
Use Add for setting multiple header values under the same key.
func (*ResponseHeader) SetArgBytes ¶
func (h *ResponseHeader) SetArgBytes(key, value []byte, noValue bool)
func (*ResponseHeader) SetBytesV ¶
func (h *ResponseHeader) SetBytesV(key string, value []byte)
SetBytesV sets the given 'key: value' header.
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.
func (*ResponseHeader) SetConnectionClose ¶
func (h *ResponseHeader) SetConnectionClose(close bool)
SetConnectionClose sets 'Connection: close' header.
func (*ResponseHeader) SetContentEncoding ¶ added in v0.5.0
func (h *ResponseHeader) SetContentEncoding(contentEncoding string)
SetContentEncoding sets Content-Encoding header value.
func (*ResponseHeader) SetContentEncodingBytes ¶ added in v0.5.0
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) SetContentLengthBytes ¶
func (h *ResponseHeader) SetContentLengthBytes(contentLength []byte)
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 save re-using the cookie after the function returns.
func (*ResponseHeader) SetHeaderLength ¶
func (h *ResponseHeader) SetHeaderLength(length int)
SetHeaderLength sets the size of header for tracer.
func (*ResponseHeader) SetNoDefaultContentType ¶
func (h *ResponseHeader) SetNoDefaultContentType(b bool)
SetNoDefaultContentType set noDefaultContentType value of ResponseHeader.
func (*ResponseHeader) SetNoDefaultDate ¶ added in v0.7.2
func (h *ResponseHeader) SetNoDefaultDate(b bool)
SetNoDefaultDate set noDefaultDate value of ResponseHeader.
func (*ResponseHeader) SetNoHTTP11
deprecated
func (h *ResponseHeader) SetNoHTTP11(b bool)
Deprecated: Use ResponseHeader.SetProtocol(consts.HTTP11) instead
Now SetNoHTTP11(true) equal to SetProtocol(consts.HTTP10) SetNoHTTP11(false) equal to SetProtocol(consts.HTTP11)
func (*ResponseHeader) SetProtocol ¶ added in v0.6.3
func (h *ResponseHeader) SetProtocol(p string)
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) StatusCode ¶
func (h *ResponseHeader) StatusCode() int
StatusCode returns response status code.
func (*ResponseHeader) Trailer ¶ added in v0.6.0
func (h *ResponseHeader) Trailer() *Trailer
Trailer returns the Trailer of HTTP Header.
func (*ResponseHeader) VisitAll ¶
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.
func (*ResponseHeader) VisitAllCookie ¶
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.
type StreamServer ¶ added in v0.5.0
type StreamServer interface {
Serve(c context.Context, conn network.StreamConn) error
}
type Trailer ¶ added in v0.6.0
type Trailer struct {
// contains filtered or unexported fields
}
func (*Trailer) Add ¶ added in v0.6.0
Add adds the given 'key: value' trailer.
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 key is forbidden by RFC 7230, section 4.1.2, Add will return error
func (*Trailer) AppendBytes ¶ added in v0.6.0
func (*Trailer) DisableNormalizing ¶ added in v0.6.0
func (t *Trailer) DisableNormalizing()
func (*Trailer) GetBytes ¶ added in v0.6.0
GetBytes return the 'Trailer' Header which is composed by the Trailer key
func (*Trailer) GetTrailers ¶ added in v0.6.0
func (t *Trailer) GetTrailers() []argsKV
func (*Trailer) IsDisableNormalizing ¶ added in v0.6.0
func (*Trailer) Peek ¶ added in v0.6.0
Peek returns trailer value for the given key.
Returned value is valid until the next call to Trailer. Do not store references to returned value. Make copies instead.
func (*Trailer) ResetSkipNormalize ¶ added in v0.6.0
func (t *Trailer) ResetSkipNormalize()
func (*Trailer) Set ¶ added in v0.6.0
Set sets the given 'key: value' trailer.
If the key is forbidden by RFC 7230, section 4.1.2, Set will return error
func (*Trailer) SetTrailers ¶ added in v0.6.0
func (*Trailer) UpdateArgBytes ¶ added in v0.6.0
type URI ¶
type URI struct { DisablePathNormalizing bool // contains filtered or unexported fields }
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) Hash ¶
Hash returns URI hash, i.e. qwe of http://aaa.com/foo/bar?baz=123#qwe .
The returned value is 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.
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.
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) 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 value is valid until the next URI method call.
func (*URI) PathOriginal ¶
PathOriginal returns the original path from requestURI passed to URI.Parse().
The returned value is 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 value is 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 value is 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.