Documentation ¶
Index ¶
- type Body
- type OnBodyCallback
- type Params
- type Request
- type Response
- func (r *Response) Attachment(reader io.Reader, size int) *Response
- func (r *Response) Bytes(body []byte) *Response
- func (r *Response) Clear() *Response
- func (r *Response) Code(code status.Code) *Response
- func (r *Response) ContentType(value string) *Response
- func (r *Response) Error(err error) *Response
- func (r *Response) File(path string) *Response
- func (r *Response) Header(key string, values ...string) *Response
- func (r *Response) Headers(headers map[string][]string) *Response
- func (r *Response) JSON(model any) (*Response, error)
- func (r *Response) RetrieveFile(path string) (*Response, error)
- func (r *Response) Reveal() response.Fields
- func (r *Response) Status(status status.Status) *Response
- func (r *Response) String(body string) *Response
- func (r *Response) TransferEncoding(value string) *Response
- func (r *Response) Write(b []byte) (n int, err error)
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OnBodyCallback ¶ added in v0.10.5
type Request ¶
type Request struct { Method method.Method Path string // Query is a key-value part of the Path Query query.Query // Params are dynamic segments, in case dynamic routing is enabled Params Params Proto proto.Proto Headers *headers.Headers Encoding headers.Encoding ContentLength int ContentType string // Upgrade is the protocol token, which is set by default to proto.Unknown. In // case it is anything else, then Upgrade header was received Upgrade proto.Proto // Remote represents remote net.Addr Remote net.Addr // Ctx is a request context. It may be filled with arbitrary data across middlewares // and handler by itself. Ctx context.Context // IsTLS describes, whether request was made via https IsTLS bool Body Body // contains filtered or unexported fields }
Request represents HTTP request
func NewRequest ¶
func NewRequest( ctx context.Context, hdrs *headers.Headers, query query.Query, response *Response, conn net.Conn, body Body, paramsMap Params, disableParamsMapClearing bool, ) *Request
NewRequest returns a new instance of request object and body gateway Must not be used externally, this function is for internal purposes only HTTP/1.1 as a protocol by default is set because if first request from user is invalid, we need to render a response using request method, but appears that default method is a null-value (proto.Unknown)
func (*Request) Clear ¶
Clear resets request headers and reads body into nowhere until completed. It is implemented to clear the request object between requests
func (*Request) Hijack ¶
Hijack the connection. Request body will be implicitly read (so if you need it you should read it before) all the body left. After handler exits, the connection will be closed, so the connection can be hijacked only once
func (*Request) JSON ¶ added in v0.7.4
JSON takes a model and returns an error if occurred. Model must be a pointer to a structure. If Content-Type header is given, but is not "application/json", then status.ErrUnsupportedMediaType will be returned. If JSON is malformed, or it doesn't match the model, then custom jsoniter error will be returned
func (*Request) Respond ¶ added in v0.8.1
Respond returns Response object.
WARNING: this method clears the response builder under the hood. As it is passed by reference, it'll be cleared EVERYWHERE along a handler
func (*Request) WasHijacked ¶
WasHijacked returns true or false, depending on whether was a connection hijacked
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func NewResponse ¶
func NewResponse() *Response
func (*Response) Attachment ¶ added in v0.5.0
Attachment sets a Response's attachment. In this case Response body will be ignored. If size <= 0, then Transfer-Encoding: chunked will be used
func (*Response) Bytes ¶ added in v0.12.0
Bytes sets the response's body to passed slice WITHOUT COPYING. Changing the passed slice later will affect the response by itself
func (*Response) Code ¶
Code sets a Response code and a corresponding status. In case of unknown code, "Unknown Status Code" will be set as a status code. In this case you should call Status explicitly
func (*Response) ContentType ¶ added in v0.5.0
ContentType sets a custom Content-Type header value.
func (*Response) Error ¶ added in v0.12.0
Error returns Response with corresponding HTTP error code, if passed error is status.HTTPError.fields. Otherwise, code is considered to be 500 Internal Server Error.fields. Note: revealing error text may be dangerous
func (*Response) File ¶
File opens a file for reading and returns a new Response with attachment, set to the file descriptor.fields. If error occurred, it'll be silently returned
func (*Response) Header ¶ added in v0.12.0
Header sets header values to a key. In case it already exists the value will be appended.
func (*Response) Headers ¶
Headers simply merges passed headers into Response. Also, it is the only way to specify a quality marker of value. In case headers were not initialized before, Response headers will be set to a passed map, so editing this map will affect Response
func (*Response) JSON ¶ added in v0.12.0
JSON receives a model (must be a pointer to the structure) and returns a new Response object and an error
func (*Response) RetrieveFile ¶ added in v0.12.0
RetrieveFile opens a file for reading and returns a new Response with attachment, set to the file descriptor.fields. If error occurred during opening a file, it'll be returned
func (*Response) Reveal ¶ added in v0.12.0
Reveal returns a struct with values, filled by builder. Used mostly in internal purposes
func (*Response) Status ¶
Status sets a custom status text. This text does not matter at all, and usually totally ignored by client, so there is actually no reasons to use this except some rare cases when you need to represent a Response status text somewhere
func (*Response) TransferEncoding ¶ added in v0.5.0
TransferEncoding sets a custom Transfer-Encoding header value.