protocol

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 149

Documentation

Index

Constants

View Source
const (
	ArgsHasValue = false
)

Variables

View Source
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
)
View Source
var (
	ServerDate     atomic.Value
	ServerDateOnce sync.Once // serverDateOnce.Do(updateServerDate)
)
View Source
var (
	ErrMissingFile = errors.NewPublic("http: no such file")
)
View Source
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.

View Source
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 AddFile

func AddFile(w *multipart.Writer, fieldName, path string) error

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 IsBadTrailer(key []byte) bool

func MarshalMultipartForm

func MarshalMultipartForm(f *multipart.Form, boundary string) ([]byte, error)

func ParseContentLength

func ParseContentLength(b []byte) (int, error)

func ParseMultipartForm

func ParseMultipartForm(r io.Reader, request *Request, size, maxInMemoryFileSize int) error

func ReadMultipartForm

func ReadMultipartForm(r io.Reader, boundary string, size, maxInMemoryFileSize int) (*multipart.Form, error)

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 SetMultipartFormWithBoundary

func SetMultipartFormWithBoundary(req *Request, m *multipart.Form, boundary string)

func SwapRequestBody

func SwapRequestBody(a, b *Request)

func SwapResponseBody

func SwapResponseBody(a, b *Response)

func UpdateServerDate

func UpdateServerDate()

func WriteMultipartForm

func WriteMultipartForm(w io.Writer, f *multipart.Form, boundary string) error

WriteMultipartForm writes the given multipart form f with the given boundary to w.

func WriteMultipartFormFile

func WriteMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r io.Reader) error

Types

type Args

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

func (*Args) Add

func (a *Args) Add(key, value string)

Add adds 'key=value' argument.

Multiple values for the same key may be added.

func (*Args) AppendBytes

func (a *Args) AppendBytes(dst []byte) []byte

AppendBytes appends query string to dst and returns the extended dst.

func (*Args) CopyTo

func (a *Args) CopyTo(dst *Args)

CopyTo copies all args to dst.

func (*Args) Del

func (a *Args) Del(key string)

Del deletes argument with the given key from query args.

func (*Args) DelBytes

func (a *Args) DelBytes(key []byte)

DelBytes deletes argument with the given key from query args.

func (*Args) Has

func (a *Args) Has(key string) bool

Has returns true if the given key exists in Args.

func (*Args) Len

func (a *Args) Len() int

Len returns the number of query args.

func (*Args) ParseBytes

func (a *Args) ParseBytes(b []byte)

ParseBytes parses the given b containing query args.

func (*Args) Peek

func (a *Args) Peek(key string) []byte

Peek returns query arg value for the given key.

Returned value is valid until the next Args call.

func (*Args) PeekAll added in v0.7.2

func (a *Args) PeekAll(key string) [][]byte

PeekAll returns all the arg values for the given key.

func (*Args) PeekExists

func (a *Args) PeekExists(key string) (string, bool)

func (*Args) QueryString

func (a *Args) QueryString() []byte

QueryString returns query string for the args.

The returned value is valid until the next call to Args methods.

func (*Args) Reset

func (a *Args) Reset()

Reset clears query args.

func (*Args) Set

func (a *Args) Set(key, value string)

Set sets 'key=value' argument.

func (*Args) String

func (a *Args) String() string

String returns string representation of query args.

func (*Args) VisitAll

func (a *Args) VisitAll(f func(key, value []byte))

VisitAll calls f for each existing arg.

f must not retain references to key and value after returning. Make key and/or value copies if you need storing them after returning.

func (*Args) WriteTo

func (a *Args) WriteTo(w io.Writer) (int64, error)

WriteTo writes query string to w.

WriteTo implements io.WriterTo interface.

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

func (c *Cookie) AppendBytes(dst []byte) []byte

AppendBytes appends cookie representation to dst and returns the extended dst.

func (*Cookie) Cookie

func (c *Cookie) Cookie() []byte

Cookie returns cookie representation.

The returned value is valid until the next call to Cookie methods.

func (*Cookie) Domain

func (c *Cookie) Domain() []byte

Domain returns cookie domain.

The returned domain is valid until the next Cookie modification method call.

func (*Cookie) Expire

func (c *Cookie) Expire() time.Time

Expire returns cookie expiration time.

CookieExpireUnlimited is returned if cookie doesn't expire

func (*Cookie) HTTPOnly

func (c *Cookie) HTTPOnly() bool

HTTPOnly returns true if the cookie is http only.

func (*Cookie) Key

func (c *Cookie) Key() []byte

Key returns cookie name.

The returned value is valid until the next Cookie modification method call.

func (*Cookie) MaxAge

func (c *Cookie) MaxAge() int

MaxAge returns the seconds until the cookie is meant to expire or 0 if no max age.

func (*Cookie) Parse

func (c *Cookie) Parse(src string) error

Parse parses Set-Cookie header.

func (*Cookie) ParseBytes

func (c *Cookie) ParseBytes(src []byte) error

ParseBytes parses Set-Cookie header.

func (*Cookie) Partitioned added in v0.8.0

func (c *Cookie) Partitioned() bool

Partitioned returns if cookie is partitioned.

func (*Cookie) Path

func (c *Cookie) Path() []byte

Path returns cookie path.

func (*Cookie) Reset

func (c *Cookie) Reset()

Reset clears the cookie.

func (*Cookie) SameSite

func (c *Cookie) SameSite() CookieSameSite

SameSite returns the SameSite mode.

func (*Cookie) Secure

func (c *Cookie) Secure() bool

Secure returns true if the cookie is secure.

func (*Cookie) SetDomain

func (c *Cookie) SetDomain(domain string)

SetDomain sets cookie domain.

func (*Cookie) SetExpire

func (c *Cookie) SetExpire(expire time.Time)

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

func (c *Cookie) SetHTTPOnly(httpOnly bool)

SetHTTPOnly sets cookie's httpOnly flag to the given value.

func (*Cookie) SetKey

func (c *Cookie) SetKey(key string)

SetKey sets cookie name.

func (*Cookie) SetKeyBytes

func (c *Cookie) SetKeyBytes(key []byte)

SetKeyBytes sets cookie name.

func (*Cookie) SetMaxAge

func (c *Cookie) SetMaxAge(seconds int)

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

func (c *Cookie) SetPartitioned(partitioned bool)

SetPartitioned sets cookie as partitioned. Setting Partitioned to true will also set Secure.

func (*Cookie) SetPath

func (c *Cookie) SetPath(path string)

SetPath sets cookie path.

func (*Cookie) SetPathBytes

func (c *Cookie) SetPathBytes(path []byte)

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) SetSecure

func (c *Cookie) SetSecure(secure bool)

SetSecure sets cookie's secure flag to the given value.

func (*Cookie) SetValue

func (c *Cookie) SetValue(value string)

SetValue sets cookie value.

func (*Cookie) SetValueBytes

func (c *Cookie) SetValueBytes(value []byte)

SetValueBytes sets cookie value.

func (*Cookie) String

func (c *Cookie) String() string

String returns cookie representation.

func (*Cookie) Value

func (c *Cookie) Value() []byte

Value returns cookie value.

The returned value is valid until the next Cookie modification method call.

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 File

type File struct {
	Name      string
	ParamName string
	io.Reader
}

File struct represent file information for multipart request

type MultipartField

type MultipartField struct {
	Param       string
	FileName    string
	ContentType string
	io.Reader
}

MultipartField struct represent custom data part for multipart request

type Proxy

type Proxy func(*Request) (*URI, error)

func ProxyURI

func ProxyURI(fixedURI *URI) Proxy

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

func NewRequest(method, url string, body io.Reader) *Request

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

func (req *Request) AppendBody(p []byte)

AppendBody appends p to request body.

It is safe re-using p after the function returns.

func (*Request) AppendBodyString

func (req *Request) AppendBodyString(s string)

AppendBodyString appends s to request body.

func (*Request) BasicAuth

func (req *Request) BasicAuth() (username, password string, ok bool)

BasicAuth can return the username and password in the request's Authorization header, if the request uses the HTTP Basic Authorization.

func (*Request) Body

func (req *Request) Body() []byte

Body returns request body. if get body failed, returns nil.

func (*Request) BodyBuffer

func (req *Request) BodyBuffer() *bytebufferpool.ByteBuffer

func (*Request) BodyBytes

func (req *Request) BodyBytes() []byte

func (*Request) BodyE

func (req *Request) BodyE() ([]byte, error)

BodyE returns request body.

func (*Request) BodyStream

func (req *Request) BodyStream() io.Reader

func (*Request) BodyWriteTo

func (req *Request) BodyWriteTo(w io.Writer) error

BodyWriteTo writes request body to w.

func (*Request) BodyWriter

func (req *Request) BodyWriter() io.Writer

BodyWriter returns writer for populating request body.

func (*Request) CloseBodyStream

func (req *Request) CloseBodyStream() error

func (*Request) ConnectionClose

func (req *Request) ConnectionClose() bool

ConnectionClose returns true if 'Connection: close' header is set.

func (*Request) ConstructBodyStream

func (req *Request) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)

func (*Request) CopyTo

func (req *Request) CopyTo(dst *Request)

CopyTo copies req contents to dst except of body stream.

func (*Request) CopyToSkipBody

func (req *Request) CopyToSkipBody(dst *Request)

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 (req *Request) HasMultipartForm() bool

func (*Request) Host

func (req *Request) Host() []byte

Host returns the host for the given request.

func (*Request) IsBodyStream

func (req *Request) IsBodyStream() bool

IsBodyStream returns true if body is set via SetBodyStream*

func (*Request) IsURIParsed

func (req *Request) IsURIParsed() bool

func (*Request) MayContinue

func (req *Request) MayContinue() bool

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) Method

func (req *Request) Method() []byte

Method returns request method

func (*Request) MultipartFields

func (req *Request) MultipartFields() []*MultipartField

func (*Request) MultipartFiles

func (req *Request) MultipartFiles() []*File

func (*Request) MultipartForm

func (req *Request) MultipartForm() (*multipart.Form, error)

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 (req *Request) MultipartFormBoundary() string

func (*Request) OnlyMultipartForm

func (req *Request) OnlyMultipartForm() bool

func (*Request) Options

func (req *Request) Options() *config.RequestOptions

func (*Request) ParseURI

func (req *Request) ParseURI()

func (*Request) Path

func (req *Request) Path() []byte

Path returns request path

func (*Request) PostArgString

func (req *Request) PostArgString() []byte

func (*Request) PostArgs

func (req *Request) PostArgs() *Args

PostArgs returns POST arguments.

func (*Request) QueryString

func (req *Request) QueryString() []byte

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

func (req *Request) RequestURI() []byte

RequestURI returns the RequestURI for the given request.

func (*Request) Reset

func (req *Request) Reset()

Reset clears request contents.

func (*Request) ResetBody

func (req *Request) ResetBody()

ResetBody resets request body.

func (*Request) ResetSkipHeader

func (req *Request) ResetSkipHeader()

func (*Request) ResetWithoutConn added in v0.6.7

func (req *Request) ResetWithoutConn()

func (*Request) Scheme

func (req *Request) Scheme() []byte

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

func (req *Request) SetAuthSchemeToken(scheme, token string)

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

func (req *Request) SetAuthToken(token string)

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

func (req *Request) SetBasicAuth(username, password string)

SetBasicAuth sets the basic authentication header in the current HTTP request.

func (*Request) SetBody

func (req *Request) SetBody(body []byte)

SetBody sets request body.

It is safe re-using body argument after the function returns.

func (*Request) SetBodyRaw

func (req *Request) SetBodyRaw(body []byte)

SetBodyRaw sets request body, but without copying it.

From this point onward the body argument must not be changed.

func (*Request) SetBodyStream

func (req *Request) SetBodyStream(bodyStream io.Reader, bodySize int)

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

func (req *Request) SetBodyString(body string)

SetBodyString sets request body.

func (*Request) SetConnectionClose

func (req *Request) SetConnectionClose()

SetConnectionClose sets 'Connection: close' header.

func (*Request) SetCookie

func (req *Request) SetCookie(key, value string)

SetCookie appends a single cookie in the current request instance.

func (*Request) SetCookies

func (req *Request) SetCookies(hc map[string]string)

SetCookies sets an array of cookies in the current request instance.

func (*Request) SetFile

func (req *Request) SetFile(param, filePath string)

SetFile sets single file field name and its path for multipart upload.

func (*Request) SetFileReader

func (req *Request) SetFileReader(param, fileName string, reader io.Reader)

SetFileReader sets single file using io.Reader for multipart upload.

func (*Request) SetFiles

func (req *Request) SetFiles(files map[string]string)

SetFiles sets multiple file field name and its path for multipart upload.

func (*Request) SetFormData

func (req *Request) SetFormData(data map[string]string)

SetFormData sets x-www-form-urlencoded params

func (*Request) SetFormDataFromValues

func (req *Request) SetFormDataFromValues(data url.Values)

SetFormDataFromValues sets x-www-form-urlencoded params from url values.

func (*Request) SetHeader

func (req *Request) SetHeader(header, value string)

SetHeader sets a single header field and its value in the current request.

func (*Request) SetHeaders

func (req *Request) SetHeaders(headers map[string]string)

SetHeaders sets multiple header field and its value in the current request.

func (*Request) SetHost

func (req *Request) SetHost(host string)

SetHost sets host for the request.

func (*Request) SetIsTLS

func (req *Request) SetIsTLS(isTLS bool)

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 (req *Request) SetMaxKeepBodySize(n int)

func (*Request) SetMethod

func (req *Request) SetMethod(method string)

SetMethod sets http method for this request.

func (*Request) SetMultipartField

func (req *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader)

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

func (req *Request) SetMultipartFormBoundary(b string)

SetMultipartFormBoundary will set the multipart form boundary for the request.

func (*Request) SetMultipartFormData

func (req *Request) SetMultipartFormData(data map[string]string)

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

func (req *Request) SetQueryString(queryString string)

SetQueryString sets query string.

func (*Request) SetRequestURI

func (req *Request) SetRequestURI(requestURI string)

SetRequestURI sets RequestURI.

func (*Request) SwapBody

func (req *Request) SwapBody(body []byte) []byte

SwapBody swaps request body with the given body and returns the previous request body.

It is forbidden to use the body passed to SwapBody after the function returns.

func (*Request) URI

func (req *Request) URI() *URI

URI returns request URI

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) Host

func (h *RequestHeader) Host() []byte

Host returns Host header value.

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) Reset

func (h *RequestHeader) Reset()

Reset clears request header.

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

func (resp *Response) AppendBody(p []byte)

AppendBody appends p to response body.

It is safe re-using p after the function returns.

func (*Response) AppendBodyString

func (resp *Response) AppendBodyString(s string)

AppendBodyString appends s to response body.

func (*Response) Body

func (resp *Response) Body() []byte

Body returns response body. if get body failed, returns nil.

func (*Response) BodyBuffer

func (resp *Response) BodyBuffer() *bytebufferpool.ByteBuffer

func (*Response) BodyBytes

func (resp *Response) BodyBytes() []byte

func (*Response) BodyE

func (resp *Response) BodyE() ([]byte, error)

BodyE returns response body.

func (*Response) BodyGunzip

func (resp *Response) BodyGunzip() ([]byte, error)

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 (resp *Response) BodyStream() io.Reader

func (*Response) BodyWriteTo

func (resp *Response) BodyWriteTo(w io.Writer) error

BodyWriteTo writes response body to w.

func (*Response) BodyWriter

func (resp *Response) BodyWriter() io.Writer

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 (resp *Response) CloseBodyStream() error

func (*Response) ConnectionClose

func (resp *Response) ConnectionClose() bool

ConnectionClose returns true if 'Connection: close' header is set.

func (*Response) ConstructBodyStream

func (resp *Response) ConstructBodyStream(body *bytebufferpool.ByteBuffer, bodyStream io.Reader)

func (*Response) CopyTo

func (resp *Response) CopyTo(dst *Response)

CopyTo copies resp contents to dst except of body stream.

func (*Response) CopyToSkipBody

func (resp *Response) CopyToSkipBody(dst *Response)

func (*Response) GetHijackWriter added in v0.6.0

func (resp *Response) GetHijackWriter() network.ExtWriter

func (*Response) HasBodyBytes

func (resp *Response) HasBodyBytes() bool

func (*Response) Hijack added in v0.9.4

func (resp *Response) Hijack() (network.Conn, error)

Hijack returns the underlying network.Conn if available.

It's only available when StatusCode() == 101 and "Connection: Upgrade", coz Hertz will NOT reuse connection in this case, then make it optional for users to implement their own protocols.

The most common scenario is used with github.com/hertz-contrib/websocket

func (*Response) HijackWriter added in v0.6.0

func (resp *Response) HijackWriter(writer network.ExtWriter)

func (*Response) IsBodyStream

func (resp *Response) IsBodyStream() bool

IsBodyStream returns true if body is set via SetBodyStream*

func (*Response) LocalAddr

func (resp *Response) LocalAddr() net.Addr

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 (resp *Response) MustSkipBody() bool

func (*Response) ParseNetAddr

func (resp *Response) ParseNetAddr(conn network.Conn)

func (*Response) RemoteAddr

func (resp *Response) RemoteAddr() net.Addr

RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.

func (*Response) Reset

func (resp *Response) Reset()

Reset clears response contents.

func (*Response) ResetBody

func (resp *Response) ResetBody()

ResetBody resets response body.

func (*Response) SetBody

func (resp *Response) SetBody(body []byte)

SetBody sets response body.

It is safe re-using body argument after the function returns.

func (*Response) SetBodyRaw

func (resp *Response) SetBodyRaw(body []byte)

SetBodyRaw sets response body, but without copying it.

From this point onward the body argument must not be changed.

func (*Response) SetBodyStream

func (resp *Response) SetBodyStream(bodyStream io.Reader, bodySize int)

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

func (resp *Response) SetBodyStreamNoReset(bodyStream io.Reader, bodySize int)

SetBodyStreamNoReset is almost the same as SetBodyStream, but it doesn't reset the bodyStream before.

func (*Response) SetBodyString

func (resp *Response) SetBodyString(body string)

SetBodyString sets response body.

func (*Response) SetConnectionClose

func (resp *Response) SetConnectionClose()

SetConnectionClose sets 'Connection: close' header.

func (*Response) SetMaxKeepBodySize

func (resp *Response) SetMaxKeepBodySize(n int)

func (*Response) SetStatusCode

func (resp *Response) SetStatusCode(statusCode int)

SetStatusCode sets response status code.

func (*Response) StatusCode

func (resp *Response) StatusCode() int

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) Reset

func (h *ResponseHeader) Reset()

Reset clears response header.

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 Server

type Server interface {
	Serve(c context.Context, conn network.Conn) error
}

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

func (t *Trailer) Add(key, value string) error

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 (t *Trailer) AppendBytes(dst []byte) []byte

func (*Trailer) CopyTo added in v0.6.0

func (t *Trailer) CopyTo(dst *Trailer)

CopyTo copies all the trailer to dst.

func (*Trailer) Del added in v0.6.0

func (t *Trailer) Del(key string)

Del deletes trailer with the given key.

func (*Trailer) DisableNormalizing added in v0.6.0

func (t *Trailer) DisableNormalizing()

func (*Trailer) Empty added in v0.6.0

func (t *Trailer) Empty() bool

func (*Trailer) Get added in v0.6.0

func (t *Trailer) Get(key string) string

Get returns trailer value for the given key.

func (*Trailer) GetBytes added in v0.6.0

func (t *Trailer) GetBytes() []byte

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) Header added in v0.6.0

func (t *Trailer) Header() []byte

func (*Trailer) IsDisableNormalizing added in v0.6.0

func (t *Trailer) IsDisableNormalizing() bool

func (*Trailer) Peek added in v0.6.0

func (t *Trailer) Peek(key string) []byte

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) Reset added in v0.6.0

func (t *Trailer) Reset()

func (*Trailer) ResetSkipNormalize added in v0.6.0

func (t *Trailer) ResetSkipNormalize()

func (*Trailer) Set added in v0.6.0

func (t *Trailer) Set(key, value string) error

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 (t *Trailer) SetTrailers(trailers []byte) (err error)

func (*Trailer) UpdateArgBytes added in v0.6.0

func (t *Trailer) UpdateArgBytes(key, value []byte) error

func (*Trailer) VisitAll added in v0.6.0

func (t *Trailer) VisitAll(f func(key, value []byte))

VisitAll calls f for each header.

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 ParseURI

func ParseURI(uriStr string) *URI

func (*URI) AppendBytes

func (u *URI) AppendBytes(dst []byte) []byte

AppendBytes appends full uri to dst and returns the extended dst.

func (*URI) CopyTo

func (u *URI) CopyTo(dst *URI)

CopyTo copies uri contents to dst.

func (*URI) FullURI

func (u *URI) FullURI() []byte

FullURI returns full uri in the form {Scheme}://{Host}{RequestURI}#{Hash}.

func (*URI) Hash

func (u *URI) Hash() []byte

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

func (u *URI) Host() []byte

Host returns host part, i.e. aaa.com of http://aaa.com/foo/bar?baz=123#qwe .

Host is always lowercased.

func (*URI) LastPathSegment

func (u *URI) LastPathSegment() []byte

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

func (u *URI) Parse(host, uri []byte)

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

func (u *URI) Password() []byte

Password returns URI password

func (*URI) Path

func (u *URI) Path() []byte

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

func (u *URI) PathOriginal() []byte

PathOriginal returns the original path from requestURI passed to URI.Parse().

The returned value is valid until the next URI method call.

func (*URI) QueryArgs

func (u *URI) QueryArgs() *Args

QueryArgs returns query args.

func (*URI) QueryString

func (u *URI) QueryString() []byte

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

func (u *URI) RequestURI() []byte

RequestURI returns RequestURI - i.e. URI without Scheme and Host.

func (*URI) Reset

func (u *URI) Reset()

Reset clears uri.

func (*URI) Scheme

func (u *URI) Scheme() []byte

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) SetHash

func (u *URI) SetHash(hash string)

SetHash sets URI hash.

func (*URI) SetHashBytes

func (u *URI) SetHashBytes(hash []byte)

SetHashBytes sets URI hash.

func (*URI) SetHost

func (u *URI) SetHost(host string)

SetHost sets host for the uri.

func (*URI) SetHostBytes

func (u *URI) SetHostBytes(host []byte)

SetHostBytes sets host for the uri.

func (*URI) SetPassword

func (u *URI) SetPassword(password string)

SetPassword sets URI password.

func (*URI) SetPasswordBytes

func (u *URI) SetPasswordBytes(password []byte)

SetPasswordBytes sets URI password.

func (*URI) SetPath

func (u *URI) SetPath(path string)

SetPath sets URI path.

func (*URI) SetPathBytes

func (u *URI) SetPathBytes(path []byte)

SetPathBytes sets URI path.

func (*URI) SetQueryString

func (u *URI) SetQueryString(queryString string)

SetQueryString sets URI query string.

func (*URI) SetQueryStringBytes

func (u *URI) SetQueryStringBytes(queryString []byte)

SetQueryStringBytes sets URI query string.

func (*URI) SetScheme

func (u *URI) SetScheme(scheme string)

SetScheme sets URI scheme, i.e. http, https, ftp, etc.

func (*URI) SetSchemeBytes

func (u *URI) SetSchemeBytes(scheme []byte)

SetSchemeBytes sets URI scheme, i.e. http, https, ftp, etc.

func (*URI) SetUsername

func (u *URI) SetUsername(username string)

SetUsername sets URI username.

func (*URI) SetUsernameBytes

func (u *URI) SetUsernameBytes(username []byte)

SetUsernameBytes sets URI username.

func (*URI) String

func (u *URI) String() string

String returns full uri.

func (*URI) Update

func (u *URI) Update(newURI string)

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

func (u *URI) UpdateBytes(newURI []byte)

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.

func (*URI) Username

func (u *URI) Username() []byte

Username returns URI username

Directories

Path Synopsis
ext
req

Jump to

Keyboard shortcuts

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