package client

import "github.com/gorilla/http/client"

Installation | Overview | API | Files

Installation

$ go get github.com/gorilla/http/client

Overview

Package gorilla/http/client contains the lower level HTTP client implementation.

Package client is divided into two layers. The upper layer is the client.Client layer which handles the vaguaries of http implementations. The lower layer, two types, reader and writer are concerned with encoding and decoding the HTTP data stream on the wire.

The interface presented by client.Client is very powerful. It is not expected that normal consumers of HTTP services will need to operate at this level and should instead user the higher level interfaces in the gorilla/http package.

API

Package Files

Constants

const (
    INFO_CONTINUE           = 100
    INFO_SWITCHING_PROTOCOL = 101
    INFO_PROCESSING         = 102

    SUCCESS_OK                = 200
    SUCCESS_CREATED           = 201
    SUCCESS_ACCEPTED          = 202
    SUCCESS_NON_AUTHORITATIVE = 203
    SUCCESS_NO_CONTENT        = 204
    SUCCESS_RESET_CONTENT     = 205
    SUCCESS_PARTIAL_CONTENT   = 206
    SUCCESS_MULTI_STATUS      = 207

    REDIRECTION_MULTIPLE_CHOICES   = 300
    REDIRECTION_MOVED_PERMANENTLY  = 301
    REDIRECTION_MOVED_TEMPORARILY  = 302
    REDIRECTION_SEE_OTHER          = 303
    REDIRECTION_NOT_MODIFIED       = 304
    REDIRECTION_USE_PROXY          = 305
    REDIRECTION_TEMPORARY_REDIRECT = 307

    CLIENT_ERROR_BAD_REQUEST                     = 400
    CLIENT_ERROR_UNAUTHORIZED                    = 401
    CLIENT_ERROR_PAYMENT_REQUIRED                = 402
    CLIENT_ERROR_FORBIDDEN                       = 403
    CLIENT_ERROR_NOT_FOUND                       = 404
    CLIENT_ERROR_METHOD_NOT_ALLOWED              = 405
    CLIENT_ERROR_NOT_ACCEPTABLE                  = 406
    CLIENT_ERROR_PROXY_AUTHENTIFICATION_REQUIRED = 407
    CLIENT_ERROR_REQUEST_TIMEOUT                 = 408
    CLIENT_ERROR_CONFLICT                        = 409
    CLIENT_ERROR_GONE                            = 410
    CLIENT_ERROR_LENGTH_REQUIRED                 = 411
    CLIENT_ERROR_PRECONDITION_FAILED             = 412
    CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE        = 413
    CLIENT_ERROR_REQUEST_URI_TOO_LONG            = 414
    CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE          = 415
    CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE = 416
    CLIENT_ERROR_EXPECTATION_FAILED              = 417
    CLIENT_ERROR_UNPROCESSABLE_ENTITY            = 422
    CLIENT_ERROR_LOCKED                          = 423
    CLIENT_ERROR_FAILED_DEPENDENCY               = 424

    SERVER_ERROR_INTERNAL                   = 500
    SERVER_ERROR_NOT_IMPLEMENTED            = 501
    SERVER_ERROR_BAD_GATEWAY                = 502
    SERVER_ERROR_SERVICE_UNAVAILABLE        = 503
    SERVER_ERROR_GATEWAY_TIMEOUT            = 504
    SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED = 505
    SERVER_ERROR_INSUFFICIENT_STORAGE       = 507
)

Variables

var (
    HTTP_1_0 = Version{1, 0}
    HTTP_1_1 = Version{1, 1}
)

type Client

type Client interface {
    WriteRequest(*Request) error
    ReadResponse() (*Response, error)
}

Client represents a single connection to a http server. Client obeys KeepAlive conditions for HTTP but connection pooling is expected to be handled at a higher layer.

func NewClient

func NewClient(rw io.ReadWriter) Client

NewClient returns a Client implementation which uses rw to communicate.

type Header struct {
    Key   string
    Value string
}

Header represents a HTTP header.

type Headers

type Headers []Header

func (Headers) Len

func (h Headers) Len() int

func (Headers) Less

func (h Headers) Less(i, j int) bool

func (Headers) Swap

func (h Headers) Swap(i, j int)

type Message

type Message interface {
    ContentLength() int64
    CloseRequested() bool
}

Message represents common traits of both Requests and Responses.

type Request

type Request struct {
    Method string
    Path   string
    Query  []string
    Version

    Headers []Header

    Body io.Reader
}

Request represents a complete HTTP request.

func (*Request) ContentLength

func (r *Request) ContentLength() int64

ContentLength returns the length of the body. If the body length is not known ContentLength will return -1.

type Response

type Response struct {
    Version
    Status
    Headers []Header
    Body    io.Reader
}

Response represents an RFC2616 response.

func (*Response) CloseRequested

func (r *Response) CloseRequested() bool

CloseRequested returns if Reason includes a Connection: close header.

func (*Response) ContentLength

func (r *Response) ContentLength() int64

ContentLength returns the length of the body. If the body length is not known ContentLength will return -1.

func (*Response) TransferEncoding

func (r *Response) TransferEncoding() string

TransferEncoding returns the transfer encoding this message was transmitted with. If not is specified by the sender, "identity" is assumed.

type Status

type Status struct {
    Code   int
    Reason string
}

Status represents an HTTP status code.

func (Status) IsClientError

func (s Status) IsClientError() bool

func (Status) IsError

func (s Status) IsError() bool

func (Status) IsInformational

func (s Status) IsInformational() bool

func (Status) IsRedirect

func (s Status) IsRedirect() bool

func (Status) IsServerError

func (s Status) IsServerError() bool

func (Status) IsSuccess

func (s Status) IsSuccess() bool

func (Status) String

func (s Status) String() string

type Version

type Version struct {
    // contains filtered or unexported fields
}

Version represents a HTTP version.

func (*Version) String

func (v *Version) String() string