Documentation ¶
Overview ¶
Package httpprot implements the HTTP protocol.
Index ¶
- Constants
- Variables
- func RequestScheme(r *http.Request) string
- type Header
- type Protocol
- func (p *Protocol) BuildRequest(reqInfo interface{}) (protocols.Request, error)
- func (p *Protocol) BuildResponse(respInfo interface{}) (protocols.Response, error)
- func (p *Protocol) CreateRequest(req interface{}) (protocols.Request, error)
- func (p *Protocol) CreateResponse(resp interface{}) (protocols.Response, error)
- func (p *Protocol) NewRequestInfo() interface{}
- func (p *Protocol) NewResponseInfo() interface{}
- type Request
- func (r *Request) AddCookie(cookie *http.Cookie)
- func (r *Request) Close()
- func (r *Request) Context() context.Context
- func (r *Request) Cookie(name string) (*http.Cookie, error)
- func (r *Request) Cookies() []*http.Cookie
- func (r *Request) FetchPayload(maxPayloadSize int64) error
- func (r *Request) GetPayload() io.Reader
- func (r *Request) HTTPHeader() http.Header
- func (r *Request) Header() protocols.Header
- func (r *Request) Host() string
- func (r *Request) IsStream() bool
- func (r *Request) MetaSize() int64
- func (r *Request) Method() string
- func (r *Request) Path() string
- func (r *Request) PayloadSize() int64
- func (r *Request) Proto() string
- func (r *Request) RawPayload() []byte
- func (r *Request) RealIP() string
- func (r *Request) Scheme() string
- func (r *Request) SetHost(host string)
- func (r *Request) SetMethod(method string)
- func (r *Request) SetPath(path string)
- func (r *Request) SetPayload(payload interface{})
- func (r *Request) Std() *http.Request
- func (r *Request) ToBuilderRequest(name string) interface{}
- func (r *Request) URL() *url.URL
- type Response
- func (r *Response) Close()
- func (r *Response) FetchPayload(maxPayloadSize int64) error
- func (r *Response) GetPayload() io.Reader
- func (r *Response) HTTPHeader() http.Header
- func (r *Response) Header() protocols.Header
- func (r *Response) IsStream() bool
- func (r *Response) MetaSize() int64
- func (r *Response) PayloadSize() int64
- func (r *Response) RawPayload() []byte
- func (r *Response) SetCookie(cookie *http.Cookie)
- func (r *Response) SetPayload(payload interface{})
- func (r *Response) SetStatusCode(code int)
- func (r *Response) StatusCode() int
- func (r *Response) Std() *http.Response
- func (r *Response) ToBuilderResponse(name string) interface{}
- func (r *Response) Trailer() protocols.Trailer
Constants ¶
const DefaultMaxPayloadSize = 4 * 1024 * 1024
DefaultMaxPayloadSize is the default max allowed payload size.
Variables ¶
var ( // ErrRequestEntityTooLarge means the request entity is too large. ErrRequestEntityTooLarge = fmt.Errorf("request entity too large") )
var ErrResponseEntityTooLarge = fmt.Errorf("response entity too large, you may need to increase 'serverMaxBodySize' or set it to -1")
ErrResponseEntityTooLarge means the request entity is too large.
Functions ¶
func RequestScheme ¶
RequestScheme returns the scheme of the request.
Types ¶
type Header ¶
Header wraps the http header.
type Protocol ¶
type Protocol struct{}
Protocol implements protocols.Protocol for HTTP.
func (*Protocol) BuildRequest ¶
BuildRequest builds and returns a request according to the given reqInfo.
func (*Protocol) BuildResponse ¶
BuildResponse builds and returns a response according to the given respInfo.
func (*Protocol) CreateRequest ¶
CreateRequest creates a new request. The input argument should be a *http.Request or nil.
The caller need to handle the close of the body of the input request, if it need to be closed. Particularly, the body of the input request may be replaced, so the caller must save a reference of the original body and close it when it is no longer needed.
func (*Protocol) CreateResponse ¶
CreateResponse creates a new response. The input argument should be a *http.Response or nil.
The caller need to handle the close of the body of the input response, if it need to be closed. Particularly, the body of the input response may be replaced, so the caller must save a reference of the original body and close it when it is no longer needed.
func (*Protocol) NewRequestInfo ¶
func (p *Protocol) NewRequestInfo() interface{}
NewRequestInfo returns a new requestInfo.
func (*Protocol) NewResponseInfo ¶
func (p *Protocol) NewResponseInfo() interface{}
NewResponseInfo returns a new responseInfo.
type Request ¶
Request wraps http.Request.
The payload of the request can be replaced with a new one, but it will never replace the body of the underlying http.Request.
Code should always use payload functions of this request to read the body of the original request, and never use the Body of the original request directly.
func NewRequest ¶
NewRequest creates a new request from a standard request. If stdr is not nil, FetchPayload must be called before any read of the request body.
func (*Request) FetchPayload ¶
FetchPayload reads the body of the underlying http.Request and initializes the payload.
if maxPayloadSize is a negative number, the payload is treated as a stream. if maxPayloadSize is zero, DefaultMaxPayloadSize is used.
func (*Request) GetPayload ¶
GetPayload returns a payload reader. For non-stream payload, the returned reader is always a new one, which contains the full data. For stream payload, the function always returns the same reader.
func (*Request) HTTPHeader ¶
HTTPHeader returns the header of the request in type http.Header.
func (*Request) PayloadSize ¶
PayloadSize returns the size of the payload. If the payload is a stream, it returns the bytes count that have been currently read out.
func (*Request) RawPayload ¶
RawPayload returns the payload in []byte, the caller should not modify its content. The function panic if the payload is a stream.
func (*Request) RealIP ¶
RealIP returns the real IP of the request. TODO: if a request is cloned and modified, RealIP maybe wrong.
func (*Request) SetPayload ¶
func (r *Request) SetPayload(payload interface{})
SetPayload set the payload of the request to payload. The payload could be a string, a byte slice, or an io.Reader, and if it is an io.Reader, it will be treated as a stream, if this is not desired, please read the data to a byte slice, and set the byte slice as the payload.
func (*Request) ToBuilderRequest ¶
ToBuilderRequest wraps the request and returns the wrapper, the return value can be used in the template of the Builder filters.
type Response ¶
type Response struct { // TODO: we only need StatusCode, Header and Body, that's can avoid // using the big http.Response object. *http.Response // contains filtered or unexported fields }
Response wraps http.Response.
The payload of the response can be replaced with a new one, but it will never replace the body of the original http.Response.
Code should always use payload functions of this response to read the body of the original response, and never use the Body of the original response directly.
func NewResponse ¶
NewResponse creates a new response from a standard response. If stdr is not nil, FetchPayload must be called before any read of the response body.
func (*Response) FetchPayload ¶
FetchPayload reads the body of the underlying http.Response and initializes the payload.
if maxPayloadSize is a negative number, the payload is treated as a stream. if maxPayloadSize is zero, DefaultMaxPayloadSize is used.
func (*Response) GetPayload ¶
GetPayload returns a payload reader. For non-stream payload, the returned reader is always a new one, which contains the full data. For stream payload, the function always returns the same reader.
func (*Response) HTTPHeader ¶
HTTPHeader returns the header of the response in type http.Header.
func (*Response) PayloadSize ¶
PayloadSize returns the size of the payload. If the payload is a stream, it returns the bytes count that have been currently read out.
func (*Response) RawPayload ¶
RawPayload returns the payload in []byte, the caller should not modify its content. The function panic if the payload is a stream.
func (*Response) SetPayload ¶
func (r *Response) SetPayload(payload interface{})
SetPayload set the payload of the response to payload. The payload could be a string, a byte slice, or an io.Reader, and if it is an io.Reader, it will be treated as a stream, if this is not desired, please read the data to a byte slice, and set the byte slice as the payload.
func (*Response) SetStatusCode ¶
SetStatusCode sets the status code of the response.
func (*Response) StatusCode ¶
StatusCode returns the status code of the response.
func (*Response) ToBuilderResponse ¶
ToBuilderResponse wraps the response and returns the wrapper, the return value can be used in the template of the Builder filters.
Directories ¶
Path | Synopsis |
---|---|
Package httpheader provides HTTP Header related functions.
|
Package httpheader provides HTTP Header related functions. |
Package httpstat implements the statistics tool for HTTP traffic.
|
Package httpstat implements the statistics tool for HTTP traffic. |