Documentation ¶
Index ¶
- type Body
- func (b *Body) Callback(onBody onBodyCallback) error
- func (b *Body) Init(req *Request)
- func (b *Body) Raw() ([]byte, error)
- func (b *Body) RawCallback(onBody onBodyCallback) error
- func (b *Body) RawReader() io.Reader
- func (b *Body) Read(buff []byte) (n int, err error)
- func (b *Body) Reset() error
- func (b *Body) Value() ([]byte, error)
- type BodyReader
- type Params
- type Path
- type Request
- type Response
- func (r Response) Attachment() types.Attachment
- func (r Response) Clear() Response
- func (r Response) DiscardHeaders() Response
- func (r Response) Headers() []string
- func (r Response) WithAttachment(reader io.Reader, size int) Response
- func (r Response) WithBody(body string) Response
- func (r Response) WithBodyByte(body []byte) Response
- func (r Response) WithCode(code status.Code) Response
- func (r Response) WithContentType(value string) Response
- func (r Response) WithError(err error) Response
- func (r Response) WithFile(path string) (Response, error)
- func (r Response) WithHeader(key string, values ...string) Response
- func (r Response) WithHeaders(headers map[string][]string) Response
- func (r Response) WithJSON(model any) (Response, error)
- func (r Response) WithStatus(status status.Status) Response
- func (r Response) WithTransferEncoding(value string) Response
- func (r Response) WithWriter(cb func(io.Writer) error) (Response, error)
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶ added in v0.7.0
type Body struct {
// contains filtered or unexported fields
}
func (*Body) Callback ¶ added in v0.7.0
Callback takes a function, that'll be called with body piece every time it's received. In case error is returned from the callback, it'll also be returned from this method
func (*Body) Raw ¶ added in v0.7.0
Raw returns RAW representation of the body. This means, that it may be encoded. If you want a decoded body, then use Value() method instead
func (*Body) RawCallback ¶ added in v0.7.0
RawCallback does the same as Callback, but body pieces aren't prematurely decoded.
func (*Body) RawReader ¶ added in v0.7.0
RawReader returns io.Reader implementation in order to read directly from the input stream. The stream may be encoded, so highly recommended just to use the Body entity as io.Reader implementation
type BodyReader ¶
type Request ¶
type Request struct { Remote net.Addr Ctx context.Context Headers *headers.Headers Path Path ContentLength int TransferEncoding headers.TransferEncoding ContentType string Method method.Method Upgrade proto.Proto Proto proto.Proto // contains filtered or unexported fields }
Request struct represents http request About headers manager see at http/headers/headers.go:Manager Headers attribute references at that one that lays in manager
func NewRequest ¶
func NewRequest( 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 builder, associated with the request
func (*Request) WasHijacked ¶
WasHijacked returns true or false, depending on whether was a connection hijacked
type Response ¶
type Response struct { Status status.Status ContentType string TransferEncoding string Body []byte Code status.Code // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse() Response
func (Response) Attachment ¶ added in v0.5.0
func (r Response) Attachment() types.Attachment
Attachment returns response's attachment.
WARNING: do NEVER use this method in your code. It serves internal purposes ONLY
func (Response) DiscardHeaders ¶
DiscardHeaders returns response object with no any headers set.
Warning: this action is not pure. Appending new headers will cause overriding old ones
func (Response) WithAttachment ¶ added in v0.5.0
WithAttachment 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) WithBody ¶
WithBody sets a string as a response body. This will override already-existing body if it was set
func (Response) WithBodyByte ¶
WithBodyByte does all the same as Body does, but for byte slices
func (Response) WithCode ¶
WithCode 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) WithContentType ¶ added in v0.5.0
WithContentType sets a custom Content-Type header value.
func (Response) WithError ¶
WithError checks, whether the passed error is a HTTPError instance. In this case, setting response code and body to HTTPError.Code and HTTPError.Message respectively. If the check failed, simply setting the code to status.InternalServerError. Error message won't be included in the response, as this possibly can spoil project internals, creating security breaches
func (Response) WithFile ¶
WithFile opens a file for reading, and returns a new response with attachment corresponding to the file FD. In case not found or any other error, it'll be directly returned. In case error occurred while opening the file, response builder won't be affected and stay clean
func (Response) WithHeader ¶
WithHeader sets header values to a key. In case it already exists the value will be appended.
func (Response) WithHeaders ¶
WithHeaders 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) WithJSON ¶ added in v0.7.4
WithJSON receives a model (must be a pointer to the structure) and returns a new Response object and an error
func (Response) WithStatus ¶
WithStatus 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) WithTransferEncoding ¶ added in v0.5.0
WithTransferEncoding sets a custom Transfer-Encoding header value.
func (Response) WithWriter ¶
WithWriter takes a function with io.Writer receiver. This writer is the actual writer to the response body. The code accessing the writer must be wrapped into the function, as the Response builder is pretty limited in such a things. It pretends to be clear (all the methods has by-value receivers) in order to enable calls chaining, so it's pretty difficult to handle with being io.Writer-compatible
Note: returned error is ALWAYS the error returned by callback. So it may be ignored in cases, when callback constantly returns nil