client

package
v0.1.74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 8 Imported by: 20

Documentation

Index

Constants

View Source
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
)
View Source
const NewLine = "\r\n"

Variables

View Source
var (
	HTTP_1_0 = Version{Major: 1, Minor: 0}
	HTTP_1_1 = Version{Major: 1, Minor: 1}
)

Functions

This section is empty.

Types

type Client

type Client interface {
	WriteRequest(*Request) error
	ReadResponse(forceReadAll bool) (*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 {
	RawBytes               []byte
	AutomaticContentLength bool
	AutomaticHost          bool
	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 {
	Major int
	Minor int
}

Version represents a HTTP version.

func (*Version) String

func (v *Version) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL