Documentation ¶
Overview ¶
http2 is a collection of functions meant to supplement the capabilities provided by the standard "net/http" package.
Index ¶
- Constants
- func AcceptsGzipResponse(httpRequest *http.Request) bool
- func NewGzipResponseWriter(writer http.ResponseWriter, compressionLevel int) gzipResponseWriter
- type ConnectionParams
- type DialError
- type LBPoolInstanceInfo
- type LBStrategy
- type LoadBalancedPool
- func (pool *LoadBalancedPool) Close()
- func (pool *LoadBalancedPool) Do(req *http.Request) (*http.Response, error)
- func (pool *LoadBalancedPool) Get() (*http.Client, error)
- func (pool *LoadBalancedPool) GetInstancePool(instanceId int) (*SimplePool, error)
- func (pool *LoadBalancedPool) SetStrategy(strategy LBStrategy)
- func (pool *LoadBalancedPool) Update(instanceInfos []LBPoolInstanceInfo)
- type Pool
- type SimplePool
Constants ¶
const ( GzipEncoding string = "gzip" AcceptEncodingHeader = "Accept-Encoding" ContentTypeHeader = "Content-Type" ContentEncodingHeader = "Content-Encoding" )
const ( // Reasonable default for HTTP connect timeouts DefaultConnectTimeout = time.Second // Reasonable default for HTTP timeouts DefaultTimeout = 5 * time.Second // Reasonable default for maximum idle connections DefaultMaxIdle = 10 )
Variables ¶
This section is empty.
Functions ¶
func AcceptsGzipResponse ¶
func NewGzipResponseWriter ¶
func NewGzipResponseWriter(writer http.ResponseWriter, compressionLevel int) gzipResponseWriter
compressionLevel - one of the compression levels in the gzip package.
Types ¶
type ConnectionParams ¶
type ConnectionParams struct { // Number of idle HTTP clients we allow to remain in the pool MaxIdle int // Use SSL transport? UseSSL bool // Skip verification of server SSL certificates? SkipVerifySSL bool // Timeout for connection (includes DNS resolution) ConnectTimeout time.Duration // Timeout for waiting for an HTTP response header ResponseTimeout time.Duration // Host header to use instead of address. HostHeader *string // Dial function to use instead of the default Dial func(network, addr string) (net.Conn, error) }
func DefaultPoolParams ¶
func DefaultPoolParams() ConnectionParams
type DialError ¶
type DialError struct {
errors.DropboxError
}
type LBPoolInstanceInfo ¶
type LBStrategy ¶
type LBStrategy int
const ( // In 'RoundRobin' load balancing strategy requests are sent to // different hosts in round robin fashion. LBRoundRobin LBStrategy = 0 // In 'Fixed' load balancing strategy requests are routed to same host, // others are used only in case of failover. LBFixed LBStrategy = 1 )
type LoadBalancedPool ¶
type LoadBalancedPool struct {
// contains filtered or unexported fields
}
func NewLoadBalancedPool ¶
func NewLoadBalancedPool(params ConnectionParams) *LoadBalancedPool
func (*LoadBalancedPool) Close ¶
func (pool *LoadBalancedPool) Close()
func (*LoadBalancedPool) Do ¶
Issues an HTTP request, distributing more load to relatively unloaded instances.
func (*LoadBalancedPool) Get ¶
func (pool *LoadBalancedPool) Get() (*http.Client, error)
Checks out an HTTP connection from an instance pool, favoring less loaded instances.
func (*LoadBalancedPool) GetInstancePool ¶
func (pool *LoadBalancedPool) GetInstancePool(instanceId int) (*SimplePool, error)
Returns a SimplePool for given instanceId, or an error if it does not exist. TODO(zviad): right now this scans all instances, thus if there are a lot of instances per partition it can become very slow. If it becomes a problem, fix it!
func (*LoadBalancedPool) SetStrategy ¶
func (pool *LoadBalancedPool) SetStrategy(strategy LBStrategy)
Sets Load Balancing strategy. Must be called before pool is actually put to use.
func (*LoadBalancedPool) Update ¶
func (pool *LoadBalancedPool) Update(instanceInfos []LBPoolInstanceInfo)
type Pool ¶
type Pool interface { // Similar interface as net/http.Client.Do() // Most important note is that: Callers should close resp.Body // when done reading from it. If resp.Body is not closed, the // Client's underlying RoundTripper (typically Transport) may not // be able to re-use a persistent TCP connection to the server // for a subsequent "keep-alive" request. Do(*http.Request) (*http.Response, error) // Returns http.Client to perform http requests with, preferable // to just use Do() function instead of this. Get() (*http.Client, error) // Closes underlying connection pool. Close() }
A generic interface for HTTP connection pools
type SimplePool ¶
type SimplePool struct {
// contains filtered or unexported fields
}
Pool of persistent HTTP connections. The only limit is on the max # of idle connections we cache. Like Python's dropbox.curllib.CurlConnectionPool.
func NewSimplePool ¶
func NewSimplePool(addr string, params ConnectionParams) *SimplePool
Creates a new HTTP connection pool using the given address and pool parameters.
'addr' is a net.Dial()-style 'host:port' destination for making the TCP connection for HTTP/HTTPS traffic. It will be used as the hostname by default for virtual hosting and SSL certificate validation; if you'd like to use a different hostname, set params.HostHeader.
func (*SimplePool) Get ¶
func (pool *SimplePool) Get() (*http.Client, error)
Returns the HTTP client, which is thread-safe.
Note that we use http.Client, rather than httputil.ClientConn, despite http.Client being higher- level. This is normally a liability for backend code, but it has more robust error handling and provides functionality that's more comparable to pycurl/curllib.