Documentation ¶
Index ¶
- type RawRequest
- type Request
- func (r *Request) AddHeader(h string)
- func (r *Request) AutoSetContentLength()
- func (r *Request) AutoSetHost()
- func (r Request) GetTimeout() time.Duration
- func (r Request) Header(search string) string
- func (r Request) Host() string
- func (r Request) IsTLS() bool
- func (r Request) RequestLine() string
- func (r Request) String() string
- func (r Request) URL() string
- type Requester
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RawRequest ¶
type RawRequest struct { // TLS should be true if TLS should be used TLS bool // Hostname is the name of the host to connect to. E.g: localhost Hostname string // Port is the port to connect to. E.g.: 80 Port string // Request is the actual message to send to the server. E.g: // GET / HTTP/1.1\r\nHost:... Request string // Timeout for the request Timeout time.Duration }
RawRequest is the most basic implementation of Requester. You should probably only use it if you're doing something *really* weird
func (RawRequest) GetTimeout ¶
func (r RawRequest) GetTimeout() time.Duration
GetTimeout returns the timeout for the request
func (RawRequest) IsTLS ¶
func (r RawRequest) IsTLS() bool
IsTLS returns true if the connection should use TLS
func (RawRequest) String ¶
func (r RawRequest) String() string
String returns the message to send to the server
type Request ¶
type Request struct { // TLS should be true if TLS should be used TLS bool // Method is the HTTP verb. E.g. GET Method string // Scheme is the protocol scheme. E.g. https Scheme string // Hostname is the hostname to connect to. E.g. localhost Hostname string // Port is the port to connect to. E.g. 80 Port string // Path is the path to request. E.g. /security.txt Path string // Query is the query string of the path. E.g. q=searchterm&page=3 Query string // Fragment is the bit after the '#'. E.g. pagesection Fragment string // Proto is the protocol specifier in the first line of the request. // E.g. HTTP/1.1 Proto string // Headers is a slice of headers to send. E.g: // []string{"Host: localhost", "Accept: text/plain"} Headers []string // Body is the 'POST' data to send. E.g: // username=AzureDiamond&password=hunter2 Body string // EOL is the string that should be used for line endings. E.g. \r\n EOL string // Deadline Timeout time.Duration }
Request is the main implementation of Requester. It gives you fine-grained control over just about everything to do with the request, but with the posibility of sane defaults.
func FromURL ¶
FromURL returns a *Request for a given method and URL and any error that occured during parsing the URL. Sane defaults are set for all of *Request's fields.
func (*Request) AutoSetContentLength ¶
func (r *Request) AutoSetContentLength()
AutoSetContentLength adds a Content-Length header to the request with the length of Request.Body as the value
func (*Request) AutoSetHost ¶
func (r *Request) AutoSetHost()
AutoSetHost adds a Host header to the request using the value of Request.Hostname
func (Request) GetTimeout ¶
GetTimeout returns the timeout for a request
func (Request) Header ¶
Header finds and returns the value of a header on the request. An empty string is returned if no match is found.
func (Request) RequestLine ¶
RequestLine returns the request line. E.g. GET / HTTP/1.1
type Requester ¶
type Requester interface { // IsTLS should return true if the connection should be made using TLS IsTLS() bool // Host should return a hostname:port pair Host() string // String should return the request as a string E.g: // GET / HTTP/1.1\r\nHost:... String() string // GetTimeout returns the timeout for a request GetTimeout() time.Duration }
A Requester defines the bare minimum set of methods needed to make an HTTP request.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
A Response wraps the HTTP response from the server
func Do ¶
Do performs the HTTP request for the given Requester and returns a *Response and any error that occured
func (Response) Header ¶
Header finds and returns the value of a header on the response. An empty string is returned if no match is found.
func (Response) ParseLocation ¶
ParseLocation parses the Location header of a response, using the initial request for context on relative URLs
func (Response) StatusCode ¶
StatusCode returns the HTTP status code as a string; e.g. 200
func (Response) StatusLine ¶
StatusLine returns the HTTP status line from the response