http

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathVariablesAttribute = "PathVariables"
)

Variables

This section is empty.

Functions

func SetCookie

func SetCookie(w http.ResponseWriter, cookie *Cookie)

SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.

Types

type Context

type Context interface {
	context.Context

	WithValue(key, val any) Context
	With(request Request, response Response) Context
	WithRequest(request Request) Context
	WithResponse(response Response) Context

	IsCompleted() bool
	Abort()
	IsAborted() bool
	Request() Request
	Response() Response
}
type Cookie struct {
	Name  string
	Value string

	Path       string    // optional
	Domain     string    // optional
	Expires    time.Time // optional
	RawExpires string    // for reading cookies only

	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	MaxAge   int
	Secure   bool
	HttpOnly bool
	SameSite SameSite
	Raw      string
	Unparsed []string // Raw text of unparsed attribute-value pairs
}

func (*Cookie) String

func (c *Cookie) String() string

String returns the serialization of the cookie for use in a Cookie header (if only Name and Value are set) or a Set-Cookie response header (if other fields are set). If c is nil or c.Name is invalid, the empty string is returned.

func (*Cookie) Valid

func (c *Cookie) Valid() error

Valid reports whether the cookie is valid.

type ErrorHandler

type ErrorHandler interface {
	HandleError(ctx Context, err error)
}

type Handler

type Handler interface {
	Invoke(ctx Context) (any, error)
}

func Handle

func Handle(fn func(ctx Context) error) Handler

type HandlerChain

type HandlerChain []HandlerFunction

type HandlerFunction

type HandlerFunction func(ctx Context, next RequestDelegate) error

type HandlerWrapper

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

func WrapHandler

func WrapHandler(handler Handler) *HandlerWrapper

func (*HandlerWrapper) Invoke

func (w *HandlerWrapper) Invoke(ctx Context, next RequestDelegate) error

func (*HandlerWrapper) SetReturnValueHandlers

func (w *HandlerWrapper) SetReturnValueHandlers(handlers []ReturnValueHandler)

func (*HandlerWrapper) Unwrap

func (w *HandlerWrapper) Unwrap() Handler

type Method

type Method string
const (
	MethodGet     Method = "GET"
	MethodHead    Method = "HEAD"
	MethodPost    Method = "POST"
	MethodPut     Method = "PUT"
	MethodPatch   Method = "PATCH" // RFC 5789
	MethodDelete  Method = "DELETE"
	MethodConnect Method = "CONNECT"
	MethodOptions Method = "OPTIONS"
	MethodTrace   Method = "TRACE"
)

func (Method) IntValue

func (m Method) IntValue() int

type NotFoundError

type NotFoundError struct {
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type PathVariable

type PathVariable struct {
	Name  string
	Value string
}

type PathVariables

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

func (*PathVariables) Put

func (p *PathVariables) Put(name string, value string)

func (*PathVariables) Value

func (p *PathVariables) Value(name string) (string, bool)

type Request

type Request interface {
	WithReader(reader io.Reader) Request
	Context() Context

	Cookie(name string) (*Cookie, bool)
	Cookies() []*Cookie

	QueryParameter(name string) (string, bool)
	QueryParameterNames() []string
	QueryParameters(name string) []string
	QueryString() string

	Header(name string) (string, bool)
	HeaderNames() []string
	Headers(name string) []string

	Path() string
	Method() Method
	Reader() io.Reader
	Scheme() string
	IsSecure() bool
}

type RequestDelegate

type RequestDelegate interface {
	Invoke(ctx Context)
}

type Response

type Response interface {
	WithWriter(writer io.Writer) Response
	Context() Context
	AddCookie(cookie *Cookie)

	ContentLength() int
	SetContentLength(len int)

	CharacterEncoding() string
	SetCharacterEncoding(charset string)

	ContentType() string
	SetContentType(contentType string)

	AddHeader(name string, value string)
	SetHeader(name string, value string)
	DeleteHeader(name string)
	Header(name string) string
	HeaderNames() []string
	Headers(name string) []string
	Status() Status
	SetStatus(status Status)

	Writer() io.Writer
	Flush()
	IsCommitted() bool
	Reset()
}

type ReturnValueHandler

type ReturnValueHandler interface {
	SupportsReturnType(returnType reflect.Type) bool
	HandleReturnValue(ctx Context, returnValue any) error
}

type SameSite

type SameSite int

SameSite allows a server to define a cookie attribute making it impossible for the browser to send this cookie along with cross-site requests. The main goal is to mitigate the risk of cross-origin information leakage, and provide some protection against cross-site request forgery attacks.

See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.

const (
	SameSiteDefaultMode SameSite = iota + 1
	SameSiteLaxMode
	SameSiteStrictMode
	SameSiteNoneMode
)

type Status

type Status int
const (
	StatusContinue           Status = 100 // RFC 9110, 15.2.1
	StatusSwitchingProtocols Status = 101 // RFC 9110, 15.2.2
	StatusProcessing         Status = 102 // RFC 2518, 10.1
	StatusEarlyHints         Status = 103 // RFC 8297

	StatusOK                   Status = 200 // RFC 9110, 15.3.1
	StatusCreated              Status = 201 // RFC 9110, 15.3.2
	StatusAccepted             Status = 202 // RFC 9110, 15.3.3
	StatusNonAuthoritativeInfo Status = 203 // RFC 9110, 15.3.4
	StatusNoContent            Status = 204 // RFC 9110, 15.3.5
	StatusResetContent         Status = 205 // RFC 9110, 15.3.6
	StatusPartialContent       Status = 206 // RFC 9110, 15.3.7
	StatusMultiStatus          Status = 207 // RFC 4918, 11.1
	StatusAlreadyReported      Status = 208 // RFC 5842, 7.1
	StatusIMUsed               Status = 226 // RFC 3229, 10.4.1

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

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

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

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

HTTP status codes as registered with IANA. See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

func (Status) String

func (code Status) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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