Documentation ¶
Overview ¶
Package http contains different http 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 ¶
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 = "X-Request-ID" // 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 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 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 Response ¶
type Response interface {
Body() []byte
}
Response is a standardized response interface.
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.