http

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package http provides HTTP common types definition.

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 */

)
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",
	}
)
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 Definitions",
		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 Database",
		StatusLoopDetected:                  "Loop Detected",
		StatusNotExtended:                   "Not Extended",
		StatusNetworkAuthenticationRequired: "Network Authentication Required",
	}
)

Functions

This section is empty.

Types

type Error

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

Error represents an HTTP error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

func (*Error) StatusCode

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 ParseHeader

func ParseHeader(value string) Header

ParseHeader parses the Header from string.

func (Header) MarshalJSON

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

MarshalJSON outputs the Header as a json.

func (Header) String

func (h Header) String() string

String outputs the Header as a string.

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the Header from json.

func (Header) Validate

func (h Header) Validate() bool

Validate returns true if the Header is valid.

type Headers

type Headers map[Header]string

Headers represents a collection of HTTP headers.

type IError

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

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 ParseMethod

func ParseMethod(value string) Method

ParseMethod parses the Method from string.

func (Method) MarshalJSON

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

MarshalJSON outputs the Method as a json.

func (Method) String

func (m Method) String() string

String outputs the Method as a string.

func (*Method) UnmarshalJSON

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

UnmarshalJSON parses the Method from json.

func (Method) Validate

func (m Method) Validate() bool

Validate returns true if the Method is valid.

type Status

type Status uint16

Status defines an HTTP status.

func ParseStatus

func ParseStatus(value string) Status

ParseStatus parses the Status from string.

func (Status) MarshalJSON

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

MarshalJSON outputs the Status as a json.

func (Status) String

func (s Status) String() string

String outputs the Status as string.

func (*Status) UnmarshalJSON

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

UnmarshalJSON parses the Status from json.

func (Status) Validate

func (s Status) Validate() bool

Validate returns true if the Dialect is valid.

Directories

Path Synopsis
Package client provides an HTTP client.
Package client provides an HTTP client.
Package schema provides a HTTP schema definition.
Package schema provides a HTTP schema definition.

Jump to

Keyboard shortcuts

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