Documentation
¶
Overview ¶
Package httpclient provide a HTTP client factory for all code that need to make API calls. This makes it possible for auth and actual API client code to share properties such as whether the connections should be made using HTTP instead of HTTPS (Insecure) or whether server certificate checking should be bypassed (NoCertCheck). The HTTP clients created with this package also have built-in support for dumping requests and responses, the "Debug" dump format produces:
https://us-3.rightscale.com/api/clouds GET /api/clouds HTTP/1.1
GET https://us-3.rightscale.com/api/clouds Host: us-3.rightscale.com User-Agent: rsc/dev-unknown-branch Content-Type: application/json X-Api-Version: 1.5 Accept-Encoding: gzip ==> HTTP/1.1 200 OK Content-Length: 17224 Cache-Control: private, max-age=0, must-revalidate Connection: keep-alive Content-Type: application/vnd.rightscale.cloud+json;type=collection;charset=utf-8 Date: Fri, 10 Jul 2015 22:01:35 GMT Status: 200 OK Strict-Transport-Security: max-age=31536000; includeSubdomains; X-Request-Uuid: 3b036a56a5b04b35a94dbaf8240f1016
Index ¶
Constants ¶
const UA = "rsc/dev-unknown-branch"
Variables ¶
var ( // DumpFormat dictates how HTTP requests and responses are logged: NoDump prevents logging // altogether, Debug generates logs in human readable format and JSON in JSON format. // Verbose causes all headers to be logged - including sensitive ones. DumpFormat Format // Insecure dictates whether HTTP (true) or HTTPS (false) should be used to connect to the // API endpoints. Insecure bool // NoCheckCert dictates whether the SSL handshakes should bypass X509 certificate // validation (true) or not (false). NoCertCheck bool // ResponseHeaderTimeout, if non-zero, specifies the amount of // time to wait in seconds for a server's response headers after fully // writing the request (including its body, if any). This // time does not include the time to read the response body. ResponseHeaderTimeout time.Duration = 20 * time.Second // HiddenHeaders lists headers that should not be logged unless DumpFormat is Verbose. HiddenHeaders = map[string]bool{"Authorization": true, "Cookie": true} )
var (
OsStderr io.Writer = os.Stderr
)
For tests
Functions ¶
This section is empty.
Types ¶
type Format ¶
type Format int
Request/response dump format
func (Format) IsDebug ¶
IsDebug is a convenience wrapper that returns true if the Debug bit is set on the flag.
func (Format) IsJSON ¶
IsJSON is a convenience wrapper that returns true if the JSON bit is set on the flag.
type HTTPClient ¶
type HTTPClient interface { Do(req *http.Request) (*http.Response, error) // DoHidden prevents logging, useful for requests made during authorization. DoHidden(req *http.Request) (*http.Response, error) }
Use interface instead of raw http.Client to ease testing
func New ¶
func New() HTTPClient
New returns an HTTP client using the settings specified by this package variables.
func NewNoRedirect ¶
func NewNoRedirect() HTTPClient
NewNoRedirect returns an HTTP client that does not follow redirects.