Documentation
¶
Overview ¶
Package http converts fasthttp requests to net/http requests It refers to the logic of net/http/httputil/reverseproxy.go
Index ¶
- Variables
- type BufferPool
- type ProtocolHandler
- func (dph *ProtocolHandler) GetCliOptions(_ context.Context) ([]client.Option, error)
- func (dph *ProtocolHandler) HandleErr(ctx context.Context, err error) error
- func (dph *ProtocolHandler) HandleRspBody(ctx context.Context, _ interface{}) error
- func (dph *ProtocolHandler) TransReqBody(ctx context.Context) (interface{}, error)
- func (dph *ProtocolHandler) TransRspBody(context.Context) (interface{}, error)
- func (dph *ProtocolHandler) WithCtx(ctx context.Context) (context.Context, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultProtocolHandler 默认的协议转化处理器 DefaultProtocolHandler = &ProtocolHandler{ BufferPool: objectpool.NewBytesPool(defaultBufSize), } )
View Source
var TestConnProxy = (&ProtocolHandler{}).connProxy
TestConnProxy is a variable that holds the connProxy function for testing purposes
View Source
var TestCoyBuffer = copyBuffer
TestCoyBuffer 仅测试使用
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
BufferPool is an interface for getting and returning temporary byte slices for use by io.CopyBuffer.
type ProtocolHandler ¶
type ProtocolHandler struct { // Director must be a function which modifies // the request into a new request to be sent // using Transport. Its response is then copied // back to the original client unmodified. // Director must not access the provided Request // after returning. Director func(*stdhttp.Request) // The transport used to perform proxy requests. // If nil, http.DefaultTransport is used. Transport stdhttp.RoundTripper // FlushInterval specifies the flush interval // to flush to the client while copying the // response body. // If zero, no periodic flushing is done. // A negative value means to flush immediately // after each write to the client. // The FlushInterval is ignored when ReverseProxy // recognizes a response as a streaming response, or // if its ContentLength is -1; for such responses, writes // are flushed to the client immediately. FlushInterval time.Duration // BufferPool optionally specifies a buffer pool to // get byte slices for use by io.CopyBuffer when // copying HTTP response bodies. BufferPool // ErrorHandler is an optional function that handles errors // reaching the backend or errors from ModifyResponse. // // If nil, the default is to log the provided error and return // a 502 Status Bad Gateway response. ErrorHandler func(context.Context, error) }
ProtocolHandler is the default protocol handler
func (*ProtocolHandler) GetCliOptions ¶
GetCliOptions gets specific client options for the request
func (*ProtocolHandler) HandleErr ¶
func (dph *ProtocolHandler) HandleErr(ctx context.Context, err error) error
HandleErr handles error messages
func (*ProtocolHandler) HandleRspBody ¶
func (dph *ProtocolHandler) HandleRspBody(ctx context.Context, _ interface{}) error
HandleRspBody handles the response
func (*ProtocolHandler) TransReqBody ¶
func (dph *ProtocolHandler) TransReqBody(ctx context.Context) (interface{}, error)
TransReqBody converts the request body
func (*ProtocolHandler) TransRspBody ¶
func (dph *ProtocolHandler) TransRspBody(context.Context) (interface{}, error)
TransRspBody converts the response body
Click to show internal directories.
Click to hide internal directories.