Documentation ¶
Index ¶
- Variables
- func Hijacker(request *Request, hijacker hijackConn) func() (net.Conn, error)
- type ConnectionHijacker
- type FileErrHandler
- type Render
- type Request
- type Response
- func NewResponse() Response
- func OK() Response
- func WithBody(body string) Response
- func WithBodyAppend(body string) Response
- func WithBodyByte(body []byte) Response
- func WithBodyByteAppend(body []byte) Response
- func WithCode(code status.Code) Response
- func WithError(err error) Response
- func WithFile(path string, handler FileErrHandler) Response
- func WithHeader(key string, values ...string) Response
- func WithHeaders(headers map[string][]string) Response
- func WithStatus(status status.Status) Response
- func (r Response) File() (string, FileErrHandler)
- func (r Response) Headers() headers.Headers
- func (r Response) WithBody(body string) Response
- func (r Response) WithBodyAppend(body string) Response
- func (r Response) WithBodyByte(body []byte) Response
- func (r Response) WithBodyByteAppend(body []byte) Response
- func (r Response) WithCode(code status.Code) Response
- func (r Response) WithError(err error) Response
- func (r Response) WithFile(path string, handler FileErrHandler) Response
- func (r Response) WithHeader(key string, headerValues ...string) Response
- func (r Response) WithHeaders(headers map[string][]string) Response
- func (r Response) WithStatus(status status.Status) Response
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
var ErrRead = errors.New("body has been already read")
WithResponse is just a nil-filled default pre-created response. Because of clear methods, it is anyway copied every time it is used as constructor so please, DO NOT modify fields of this variable
Functions ¶
Types ¶
type ConnectionHijacker ¶
ConnectionHijacker is for user. It returns error because it has to read full request body to stop the server in defined state. And, as we know, reading body may return an error
type FileErrHandler ¶
type Request ¶
type Request struct { Method methods.Method Path string Query url.Query Fragment string Proto proto.Proto Remote net.Addr Headers headers.Headers ContentLength uint Hijack ConnectionHijacker // 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 ¶
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) Also url.Query is being constructed right here instead of passing from outside because it has only optional purposes and buff will be nil anyway But maybe it's better to implement DI all the way we go? I don't know, maybe someone will contribute and fix this
func (*Request) Body ¶
Body is a high-level function that wraps OnBody, and the only it does is reading pieces of body into the buffer that is a nil by default, but may grow and will stay as big as it grew until the disconnect
func (*Request) OnBody ¶
OnBody is a proxy-function for r.body.Read. This method reads body in streaming processing mode by calling onBody on each body piece, and onComplete when body is over (onComplete is guaranteed to be called except situation when body is already read)
type Response ¶
type Response struct { Code status.Code Status status.Status // Body is a mutable object. But it's guaranteed that in WithResponse it will not // be modified because it's nil. This means that any data will be appended will // allocate a new underlying array Body []byte Filename string // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse() Response
func WithBody ¶
WithBody sets a string as a response body. This will override already-existing body if it was set
func WithBodyAppend ¶
WithBodyAppend appends a string to already-existing body
func WithBodyByte ¶
WithBodyByte does all the same as WithBody does, but for byte slices
func WithBodyByteAppend ¶
WithBodyByteAppend does all the same as WithBodyAppend does, but with byte slices
func 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 WithStatus explicitly
func WithError ¶
WithError simply sets a code status.InternalServerError and response body as an error text
func WithFile ¶
func WithFile(path string, handler FileErrHandler) Response
WithFile sets a file path as a file that is supposed to be uploaded as a response. WithFile replaces a response body, so in case last one is specified, it'll be ignored. In case any error occurred (file not found, or error occurred during reading, etc.), handler will be called with a raised error
func WithHeader ¶
WithHeader sets header values to a key. In case it already exists the value will be appended
func 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 WithStatus ¶
WithStatus sets a status text. Not compulsory, because http does not force us strictly checking a response code, and Unknown Status Code is still a valid response code, but you are better to do this. Be bro
func (Response) File ¶
func (r Response) File() (string, FileErrHandler)
File returns response filename and error handler
func (Response) WithBody ¶
WithBody sets a string as a response body. This will override already-existing body if it was set
func (Response) WithBodyAppend ¶
WithBodyAppend appends a string to already-existing body
func (Response) WithBodyByte ¶
WithBodyByte does all the same as WithBody does, but for byte slices
func (Response) WithBodyByteAppend ¶
WithBodyByteAppend does all the same as WithBodyAppend does, but with 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 WithStatus explicitly
func (Response) WithError ¶
WithError simply sets a code status.InternalServerError and response body as an error text
func (Response) WithFile ¶
func (r Response) WithFile(path string, handler FileErrHandler) Response
WithFile sets a file path as a file that is supposed to be uploaded as a response. WithFile replaces a response body, so in case last one is specified, it'll be ignored. In case any error occurred (file not found, or error occurred during reading, etc.), handler will be called with a raised error
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