Documentation ¶
Overview ¶
Package http contains different http clients that can be used by the request forwarder we use this for benchmarking and because fasthttp is still in beta support for redirects/behavior we may encounter in the wild needs to be tested better before we abandan an alternative
Additionally: fasthttp doesn't support context cancellation
Index ¶
- Variables
- type CaptureClient
- type CapturedRequest
- func (c *CapturedRequest) Do() (Response, error)
- func (c *CapturedRequest) SetBody(body []byte) Request
- func (c *CapturedRequest) SetContext(ctx context.Context) Request
- func (c *CapturedRequest) SetHeader(key, value string) Request
- func (c *CapturedRequest) SetHeaderBytes(key, value []byte) Request
- func (c *CapturedRequest) SetRequestURI(uri string) Request
- type Client
- type ClientType
- type FastClient
- type MakeResponseFunc
- type Request
- type Response
- type RestyClient
Constants ¶
This section is empty.
Variables ¶
var ( // XForwardedFor is a byte encoded forwarded for header. XForwardedFor = []byte(headers.XForwardedFor) // ContentType is a byte encoded content type. ContentType = []byte(headers.ContentType) // Accept is a byte encoded accept header. Accept = []byte(headers.Accept) // XRequestIDString is the string request id header. XRequestIDString = ginhelper.RequestIDHeader // XRequestID is the byte encoded request id. XRequestID = []byte(XRequestIDString) // Encoding is a bytes encoded Accept-Encoding header. Encoding = []byte(headers.AcceptEncoding) )
Headers:.
var ( // JSONType is a byte encoded json type. JSONType = []byte(gin.MIMEJSON) // EncodingTypes are encoding headers. EncodingTypes = []byte("gzip, br, deflate") )
Mime types.
var AllClientTypes []ClientType
AllClientTypes is a list of all client types. Since we use stringer we can auto generate this at runtime.
var ( // OmniRPCValue is a byte encoded omnirpc string. OmniRPCValue = []byte("omnirpc") )
Constant Strings.
var ( // PostType is used for posting. PostType = []byte(http.MethodPost) )
Method types.
Functions ¶
This section is empty.
Types ¶
type CaptureClient ¶ added in v0.0.15
type CaptureClient struct {
// contains filtered or unexported fields
}
CaptureClient is a mock client used for checking response values.
func NewCaptureClient ¶ added in v0.0.15
func NewCaptureClient(responseFunc MakeResponseFunc) *CaptureClient
NewCaptureClient creates anew client for testing.
func (*CaptureClient) NewRequest ¶ added in v0.0.15
func (c *CaptureClient) NewRequest() Request
NewRequest creates a new request.
func (*CaptureClient) Requests ¶ added in v0.0.15
func (c *CaptureClient) Requests() []*CapturedRequest
Requests turns a list of sent requests. These are not mutation safe.
type CapturedRequest ¶ added in v0.0.15
type CapturedRequest struct { // ClientContains the capture client object Client *CaptureClient // Body is the request body Body []byte // Context is the request set by the client // nolint: containedctx Context context.Context // StringHeaders are headers set by SetHeader. Notably, this will not // include headers set by SetHeaderBytes StringHeaders map[string]string // StringHeaders are headers set by SetHeaderBytes. Notably, this will not // include headers set by SetHeader ByteHeaders bytemap.ByteSliceMap[[]byte] // RequestURI is the request uri bytes. Notably, this will not include // RequestURI's set by SetRequestURIBytes RequestURI string // RequestURIBytes is the request uri bytes. Notably, this will not include // RequestURI's set by SetRequestURI RequestURIBytes []byte }
CapturedRequest stores all request data for testing.
func (*CapturedRequest) Do ¶ added in v0.0.15
func (c *CapturedRequest) Do() (Response, error)
Do calls responseFunc for testing.
func (*CapturedRequest) SetBody ¶ added in v0.0.15
func (c *CapturedRequest) SetBody(body []byte) Request
SetBody stores the body for testing.
func (*CapturedRequest) SetContext ¶ added in v0.0.15
func (c *CapturedRequest) SetContext(ctx context.Context) Request
SetContext stores the context for testing.
func (*CapturedRequest) SetHeader ¶ added in v0.0.15
func (c *CapturedRequest) SetHeader(key, value string) Request
SetHeader sets the header for testing.
func (*CapturedRequest) SetHeaderBytes ¶ added in v0.0.15
func (c *CapturedRequest) SetHeaderBytes(key, value []byte) Request
SetHeaderBytes sets header bytes for testing.
func (*CapturedRequest) SetRequestURI ¶ added in v0.0.15
func (c *CapturedRequest) SetRequestURI(uri string) Request
SetRequestURI stores the request uri.
type Client ¶
type Client interface { // NewRequest creates a new request NewRequest() Request }
Client contains a post client for interacting with json rpc servers.
func NewClient ¶
func NewClient(clientType ClientType) Client
NewClient creates a client from the client type defaults to fast http.
func NewFastHTTPClient ¶
func NewFastHTTPClient() Client
NewFastHTTPClient creates a new fasthttp client. while substantially faster than resty, this can be a bad choice in certain cases:
- Context Cancellation not respected: fasthttp does not support context cancellation, so we hardcode a timeout here this is less than ideal and puts additional load on both the application and rpc servers since we pessimistically fetch
func NewRestyClient ¶
func NewRestyClient() Client
NewRestyClient creates a resty client. while much slower than fasthttp, this client requests context cancellation.
type ClientType ¶
type ClientType uint16
ClientType is the client type to use
const ( // FastHTTP is the fast http client type. FastHTTP ClientType = 0 // FastHTTP // Resty is the resty client type. Resty ClientType = iota // Resty )
func ClientTypeFromString ¶
func ClientTypeFromString(clientType string) ClientType
ClientTypeFromString returns a client type from a string.
func (ClientType) String ¶
func (i ClientType) String() string
type FastClient ¶
type FastClient interface { Do(req *fasthttp.Request, resp *fasthttp.Response) error DoDeadline(req *fasthttp.Request, resp *fasthttp.Response, deadline time.Time) error DoTimeout(req *fasthttp.Request, resp *fasthttp.Response, deadline time.Duration) error }
FastClient is an interface for storing both fasthttp.Clients and fasthttp.HostClients.
type MakeResponseFunc ¶ added in v0.0.15
type MakeResponseFunc func(c *CapturedRequest) (Response, error)
MakeResponseFunc is used for mocking responses.
type Request ¶
type Request interface { // SetBody sets the request body SetBody(body []byte) Request // SetContext sets the context for the request SetContext(ctx context.Context) Request // SetHeader sets the header for the client SetHeader(key, value string) Request // SetHeaderBytes sets header in bytes to avoid a copy SetHeaderBytes(key, value []byte) Request // SetRequestURI sets the uri for the request SetRequestURI(uri string) Request // Do makes the actual request Do() (Response, error) }
Request is a request builder.
type RestyClient ¶
type RestyClient struct {
// contains filtered or unexported fields
}
RestyClient is a resty client for making requests to the http client.
func (RestyClient) NewRequest ¶
func (r RestyClient) NewRequest() Request
NewRequest create a new request.