http

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusInvalid            Status = iota
	StatusContinue                  = 100 // RFC 7231, 6.2.1
	StatusSwitchingProtocols        = 101 // RFC 7231, 6.2.2
	StatusProcessing                = 102 // RFC 2518, 10.1
	StatusEarlyHints                = 103 // RFC 8297

	StatusOK                   = 200 // RFC 7231, 6.3.1
	StatusCreated              = 201 // RFC 7231, 6.3.2
	StatusAccepted             = 202 // RFC 7231, 6.3.3
	StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4
	StatusNoContent            = 204 // RFC 7231, 6.3.5
	StatusResetContent         = 205 // RFC 7231, 6.3.6
	StatusPartialContent       = 206 // RFC 7233, 4.1
	StatusMultiStatus          = 207 // RFC 4918, 11.1
	StatusAlreadyReported      = 208 // RFC 5842, 7.1
	StatusIMUsed               = 226 // RFC 3229, 10.4.1

	StatusMultipleChoices  = 300 // RFC 9110, 15.4.1
	StatusMovedPermanently = 301 // RFC 9110, 15.4.2
	StatusFound            = 302 // RFC 9110, 15.4.3
	StatusSeeOther         = 303 // RFC 9110, 15.4.4
	StatusNotModified      = 304 // RFC 9110, 15.4.5
	StatusUseProxy         = 305 // RFC 9110, 15.4.6

	StatusTemporaryRedirect = 307 // RFC 9110, 15.4.8
	StatusPermanentRedirect = 308 // RFC 9110, 15.4.9

	StatusBadRequest                   = 400 // RFC 9110, 15.5.1
	StatusUnauthorized                 = 401 // RFC 9110, 15.5.2
	StatusPaymentRequired              = 402 // RFC 9110, 15.5.3
	StatusForbidden                    = 403 // RFC 9110, 15.5.4
	StatusNotFound                     = 404 // RFC 9110, 15.5.5
	StatusMethodNotAllowed             = 405 // RFC 9110, 15.5.6
	StatusNotAcceptable                = 406 // RFC 9110, 15.5.7
	StatusProxyAuthRequired            = 407 // RFC 9110, 15.5.8
	StatusRequestTimeout               = 408 // RFC 9110, 15.5.9
	StatusConflict                     = 409 // RFC 9110, 15.5.10
	StatusGone                         = 410 // RFC 9110, 15.5.11
	StatusLengthRequired               = 411 // RFC 9110, 15.5.12
	StatusPreconditionFailed           = 412 // RFC 9110, 15.5.13
	StatusRequestEntityTooLarge        = 413 // RFC 9110, 15.5.14
	StatusRequestURITooLong            = 414 // RFC 9110, 15.5.15
	StatusUnsupportedMediaType         = 415 // RFC 9110, 15.5.16
	StatusRequestedRangeNotSatisfiable = 416 // RFC 9110, 15.5.17
	StatusExpectationFailed            = 417 // RFC 9110, 15.5.18
	StatusTeapot                       = 418 // RFC 9110, 15.5.19 (Unused)
	StatusMisdirectedRequest           = 421 // RFC 9110, 15.5.20
	StatusUnprocessableEntity          = 422 // RFC 9110, 15.5.21
	StatusLocked                       = 423 // RFC 4918, 11.3
	StatusFailedDependency             = 424 // RFC 4918, 11.4
	StatusTooEarly                     = 425 // RFC 8470, 5.2.
	StatusUpgradeRequired              = 426 // RFC 9110, 15.5.22
	StatusPreconditionRequired         = 428 // RFC 6585, 3
	StatusTooManyRequests              = 429 // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge  = 431 // RFC 6585, 5
	StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3

	StatusInternalServerError           = 500 // RFC 9110, 15.6.1
	StatusNotImplemented                = 501 // RFC 9110, 15.6.2
	StatusBadGateway                    = 502 // RFC 9110, 15.6.3
	StatusServiceUnavailable            = 503 // RFC 9110, 15.6.4
	StatusGatewayTimeout                = 504 // RFC 9110, 15.6.5
	StatusHTTPVersionNotSupported       = 505 // RFC 9110, 15.6.6
	StatusVariantAlsoNegotiates         = 506 // RFC 2295, 8.1
	StatusInsufficientStorage           = 507 // RFC 4918, 11.5
	StatusLoopDetected                  = 508 // RFC 5842, 7.2
	StatusNotExtended                   = 510 // RFC 2774, 7
	StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
)

Variables

View Source
var (
	// HeaderNames is a map of Header to string.
	HeaderNames = map[Header]string{}/* 119 elements not displayed */

	// ErrHeaderInvalid is returned if the HTTP header is invalid.
	ErrHeaderInvalid = errors.New("invalid http header")
)
View Source
var (
	// MethodNames is a map of Method to string.
	MethodNames = map[Method]string{
		MethodGet:     "GET",
		MethodHead:    "HEAD",
		MethodPost:    "POST",
		MethodPut:     "PUT",
		MethodDelete:  "DELETE",
		MethodConnect: "CONNECT",
		MethodOptions: "OPTIONS",
		MethodTrace:   "TRACE",
		MethodPatch:   "PATCH",
	}

	// ErrMethodInvalid is returned if the HTTP method is invalid.
	ErrMethodInvalid = errors.New("invalid http method")
)
View Source
var (
	// StatusNames is a map of Status to string.
	StatusNames = map[Status]string{
		StatusContinue:           "Continue",
		StatusSwitchingProtocols: "Switching Protocols",
		StatusProcessing:         "Processing",
		StatusEarlyHints:         "Early Hints",

		StatusOK:                   "OK",
		StatusCreated:              "Created",
		StatusAccepted:             "Accepted",
		StatusNonAuthoritativeInfo: "Non-Authoritative Information",
		StatusNoContent:            "No Content",
		StatusResetContent:         "Reset Content",
		StatusPartialContent:       "Partial Content",
		StatusMultiStatus:          "Multi-Status",
		StatusAlreadyReported:      "Already Reported",
		StatusIMUsed:               "IM Used",

		StatusMultipleChoices:   "Multiple Choices",
		StatusMovedPermanently:  "Moved Permanently",
		StatusFound:             "Found",
		StatusSeeOther:          "See Other",
		StatusNotModified:       "Not Modified",
		StatusUseProxy:          "Use Proxy",
		StatusTemporaryRedirect: "Temporary Redirect",
		StatusPermanentRedirect: "Permanent Redirect",

		StatusBadRequest:                   "Bad Request",
		StatusUnauthorized:                 "Unauthorized",
		StatusPaymentRequired:              "Payment Required",
		StatusForbidden:                    "Forbidden",
		StatusNotFound:                     "Not Found",
		StatusMethodNotAllowed:             "Method Not Allowed",
		StatusNotAcceptable:                "Not Acceptable",
		StatusProxyAuthRequired:            "Proxy Authentication Required",
		StatusRequestTimeout:               "Request Timeout",
		StatusConflict:                     "Conflict",
		StatusGone:                         "Gone",
		StatusLengthRequired:               "Length Required",
		StatusPreconditionFailed:           "Precondition Failed",
		StatusRequestEntityTooLarge:        "Request Entity Too Large",
		StatusRequestURITooLong:            "Request URI Too Long",
		StatusUnsupportedMediaType:         "Unsupported Media Type",
		StatusRequestedRangeNotSatisfiable: "Requested Range Not Satisfiable",
		StatusExpectationFailed:            "Expectation Failed",
		StatusTeapot:                       "I'm a teapot",
		StatusMisdirectedRequest:           "Misdirected Request",
		StatusUnprocessableEntity:          "Unprocessable Entity",
		StatusLocked:                       "Locked",
		StatusFailedDependency:             "Failed Dependency",
		StatusTooEarly:                     "Too Early",
		StatusUpgradeRequired:              "Upgrade Required",
		StatusPreconditionRequired:         "Precondition Required",
		StatusTooManyRequests:              "Too Many Requests",
		StatusRequestHeaderFieldsTooLarge:  "Request Header Fields Too Large",
		StatusUnavailableForLegalReasons:   "Unavailable For Legal Reasons",

		StatusInternalServerError:           "Internal Server Error",
		StatusNotImplemented:                "Not Implemented",
		StatusBadGateway:                    "Bad Gateway",
		StatusServiceUnavailable:            "Service Unavailable",
		StatusGatewayTimeout:                "Gateway Timeout",
		StatusHTTPVersionNotSupported:       "HTTP Version Not Supported",
		StatusVariantAlsoNegotiates:         "Variant Also Negotiates",
		StatusInsufficientStorage:           "Insufficient Storage",
		StatusLoopDetected:                  "Loop Detected",
		StatusNotExtended:                   "Not Extended",
		StatusNetworkAuthenticationRequired: "Network Authentication Required",
	}

	// ErrStatusInvalid is returned if the HTTP status is invalid.
	ErrStatusInvalid = errors.New("invalid http status")
)

Functions

This section is empty.

Types

type Error added in v1.2.3

type Error struct {
	Status  Status `json:"status" yaml:"Status"`
	Message string `json:"message" yaml:"Message"`
}

Error represents an HTTP error.

func (*Error) Error added in v1.2.3

func (e *Error) Error() string

Error returns the error message.

func (*Error) StatusCode added in v1.2.3

func (e *Error) StatusCode() Status

StatusCode returns the HTTP status code.

type Header uint16

Header defines an HTTP header.

const (
	HeaderInvalid Header = iota //

	// Authentication
	HeaderAuthorization // RFC 7235, 4.2
	HeaderProxyAuthenticate
	HeaderProxyAuthorization
	HeaderWWWAuthenticate

	// Caching
	HeaderAge
	HeaderCacheControl
	HeaderClearSiteData
	HeaderExpires
	HeaderPragma
	HeaderWarning

	// Client hints
	HeaderAcceptCH
	HeaderAcceptCHLifetime
	HeaderContentDPR
	HeaderDPR
	HeaderEarlyData
	HeaderSaveData
	HeaderViewportWidth
	HeaderWidth

	// Conditionals
	HeaderETag
	HeaderIfMatch
	HeaderIfModifiedSince
	HeaderIfNoneMatch
	HeaderIfUnmodifiedSince
	HeaderLastModified
	HeaderVary

	// Connection management
	HeaderConnection
	HeaderKeepAlive
	HeaderProxyConnection

	// Content negotiation
	HeaderAccept
	HeaderAcceptCharset
	HeaderAcceptEncoding
	HeaderAcceptLanguage

	// Controls
	HeaderCookie
	HeaderExpect
	HeaderMaxForwards
	HeaderSetCookie

	// CORS
	HeaderAccessControlAllowCredentials
	HeaderAccessControlAllowHeaders
	HeaderAccessControlAllowMethods
	HeaderAccessControlAllowOrigin
	HeaderAccessControlExposeHeaders
	HeaderAccessControlMaxAge
	HeaderAccessControlRequestHeaders
	HeaderAccessControlRequestMethod
	HeaderOrigin
	HeaderTimingAllowOrigin
	HeaderXPermittedCrossDomainPolicies

	// Do Not Track
	HeaderDNT
	HeaderTk

	// Downloads
	HeaderContentDisposition

	// Message body information
	HeaderContentEncoding
	HeaderContentLanguage
	HeaderContentLength
	HeaderContentLocation
	HeaderContentType

	// Proxies
	HeaderForwarded
	HeaderVia
	HeaderXForwardedFor
	HeaderXForwardedHost
	HeaderXForwardedProto

	// Redirects
	HeaderLocation

	// Request context
	HeaderFrom
	HeaderHost
	HeaderReferer
	HeaderReferrerPolicy
	HeaderUserAgent

	// Response context
	HeaderAllow
	HeaderServer

	// Range requests
	HeaderAcceptRanges
	HeaderContentRange
	HeaderIfRange
	HeaderRange

	// Security
	HeaderContentSecurityPolicy
	HeaderContentSecurityPolicyReportOnly
	HeaderCrossOriginResourcePolicy
	HeaderExpectCT
	HeaderFeaturePolicy
	HeaderPublicKeyPins
	HeaderPublicKeyPinsReportOnly
	HeaderStrictTransportSecurity
	HeaderUpgradeInsecureRequests
	HeaderXContentTypeOptions
	HeaderXDownloadOptions
	HeaderXFrameOptions
	HeaderXPoweredBy
	HeaderXXSSProtection

	// Server-sent event
	HeaderLastEventID
	HeaderNEL
	HeaderPingFrom
	HeaderPingTo
	HeaderReportTo

	// Transfer coding
	HeaderTE
	HeaderTrailer
	HeaderTransferEncoding

	// WebSockets
	HeaderSecWebSocketAccept
	HeaderSecWebSocketExtensions
	HeaderSecWebSocketKey
	HeaderSecWebSocketProtocol
	HeaderSecWebSocketVersion

	// Other
	HeaderAcceptPatch
	HeaderAcceptPushPolicy
	HeaderAcceptSignature
	HeaderAltSvc
	HeaderDate
	HeaderIndex
	HeaderLargeAllocation
	HeaderLink
	HeaderPushPolicy
	HeaderRetryAfter
	HeaderServerTiming
	HeaderSignature
	HeaderSignedHeaders
	HeaderSourceMap
	HeaderUpgrade
	HeaderXDNSPrefetchControl
	HeaderXPingback
	HeaderXRequestedWith
	HeaderXRobotsTag
	HeaderXUACompatible
)

Common HTTP headers, these are defined in RFC 7231 section 4.3.

func MustParseHeader added in v1.2.2

func MustParseHeader(name string) Header

MustParseHeader parses header string or panics.

func ParseHeader added in v1.2.2

func ParseHeader(name string) Header

ParseHeader parses header string.

func (Header) MarshalJSON added in v1.2.2

func (m Header) MarshalJSON() ([]byte, error)

MarshalJSON header to json

func (Header) String added in v1.2.2

func (m Header) String() string

String header to string

func (*Header) UnmarshalJSON added in v1.2.2

func (m *Header) UnmarshalJSON(b []byte) error

UnmarshalJSON header from json

type Headers added in v1.2.2

type Headers map[Header]string

Headers represents a collection of HTTP headers.

type IError added in v1.2.3

type IError interface {
	error

	// StatusCode returns the HTTP status code of the error
	StatusCode() Status
}

IError defines the interface for an HTTP error.

func NewError added in v1.2.3

func NewError(status Status, message ...string) IError

NewError creates a new Error instance.

type Method

type Method uint8

Method defines an HTTP method.

const (
	MethodInvalid Method = iota //
	MethodGet                   // RFC 7231, 4.3.1
	MethodHead                  // RFC 7231, 4.3.2
	MethodPost                  // RFC 7231, 4.3.3
	MethodPut                   // RFC 7231, 4.3.4
	MethodDelete                // RFC 7231, 4.3.5
	MethodConnect               // RFC 7231, 4.3.6
	MethodOptions               // RFC 7231, 4.3.7
	MethodTrace                 // RFC 7231, 4.3.8
	MethodPatch                 // RFC 5789
)

Common HTTP methods, these are defined in RFC 7231 section 4.3.

func MustParseMethod

func MustParseMethod(name string) Method

MustParseMethod parses method string or panics.

func ParseMethod

func ParseMethod(name string) Method

ParseMethod parses method string.

func (Method) MarshalJSON

func (m Method) MarshalJSON() ([]byte, error)

MarshalJSON method to json

func (Method) String

func (m Method) String() string

String method to string

func (*Method) UnmarshalJSON

func (m *Method) UnmarshalJSON(b []byte) error

UnmarshalJSON method from json

type Status added in v1.2.2

type Status uint16

Status defines an HTTP status.

func MustParseStatus added in v1.2.2

func MustParseStatus(name string) Status

MustParseStatus parses status string or panics.

func ParseStatus added in v1.2.2

func ParseStatus(name string) Status

ParseStatus parses status string.

func (Status) MarshalJSON added in v1.2.2

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON status to json

func (Status) String added in v1.2.2

func (s Status) String() string

String status to string

func (*Status) UnmarshalJSON added in v1.2.2

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON status from json

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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