ht

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Accept                        = "Accept"
	AcceptCharset                 = "Accept-Charset"
	AcceptEncoding                = "Accept-Encoding"
	AcceptLanguage                = "Accept-Language"
	Authorization                 = "Authorization"
	CacheControl                  = "Cache-Control"
	ContentLength                 = "Content-Length"
	ContentMD5                    = "Content-MD5"
	ContentType                   = "Content-Type"
	DoNotTrack                    = "DNT"
	IfMatch                       = "If-Match"
	IfModifiedSince               = "If-Modified-Since"
	IfNoneMatch                   = "If-None-Match"
	IfRange                       = "If-Range"
	IfUnmodifiedSince             = "If-Unmodified-Since"
	MaxForwards                   = "Max-Forwards"
	ProxyAuthorization            = "Proxy-Authorization"
	Pragma                        = "Pragma"
	Range                         = "Range"
	Referer                       = "Referer"
	UserAgent                     = "User-Agent"
	TE                            = "TE"
	Via                           = "Via"
	Warning                       = "Warning"
	Cookie                        = "Cookie"
	Origin                        = "Origin"
	AcceptDatetime                = "Accept-Datetime"
	XRequestedWith                = "X-Requested-With"
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlRequestMethod    = "Access-Control-Request-Method"
	AccessControlRequestHeaders   = "Access-Control-Request-Headers"
	AcceptPatch                   = "Accept-Patch"
	AcceptRanges                  = "Accept-Ranges"
	Allow                         = "Allow"
	ContentEncoding               = "Content-Encoding"
	ContentLanguage               = "Content-Language"
	ContentLocation               = "Content-Location"
	ContentDisposition            = "Content-Disposition"
	ContentRange                  = "Content-Range"
	ETag                          = "ETag"
	Expires                       = "Expires"
	LastModified                  = "Last-Modified"
	Link                          = "Link"
	Location                      = "Location"
	P3P                           = "P3P"
	ProxyAuthenticate             = "Proxy-Authenticate"
	Refresh                       = "Refresh"
	RetryAfter                    = "Retry-After"
	Server                        = "Server"
	SetCookie                     = "Set-Cookie"
	StrictTransportSecurity       = "Strict-Transport-Security"
	TransferEncoding              = "Transfer-Encoding"
	Upgrade                       = "Upgrade"
	Vary                          = "Vary"
	WWWAuthenticate               = "WWW-Authenticate"

	// Non-Standard
	XFrameOptions          = "X-Frame-Options"
	XXSSProtection         = "X-XSS-Protection"
	ContentSecurityPolicy  = "Content-Security-Policy"
	XContentSecurityPolicy = "X-Content-Security-Policy"
	XWebKitCSP             = "X-WebKit-CSP"
	XContentTypeOptions    = "X-Content-Type-Options"
	XPoweredBy             = "X-Powered-By"
	XUACompatible          = "X-UA-Compatible"
	XForwardedProto        = "X-Forwarded-Proto"
	XHTTPMethodOverride    = "X-HTTP-Method-Override"
	XForwardedFor          = "X-Forwarded-For"
	XRealIP                = "X-Real-IP"
	XCSRFToken             = "X-CSRF-Token"
	XRatelimitLimit        = "X-Ratelimit-Limit"
	XRatelimitRemaining    = "X-Ratelimit-Remaining"
	XRatelimitReset        = "X-Ratelimit-Reset"
)

Variables

This section is empty.

Functions

func Handle

func Handle[H Handler](h H) func(w http.ResponseWriter, req *http.Request)

func NormalizeHeader

func NormalizeHeader(header string) string

Normalize formats the input header to the formation of "Xxx-Xxx".

func Redirect

func Redirect(url string) (int, string, func(io.Writer))

Types

type BodyHandler

type BodyHandler func(*url.Values, io.Reader) (int, string, func(io.Writer))

type ChainHandler

type ChainHandler func(w http.ResponseWriter, req *http.Request) bool

func BasicAuthHandler

func BasicAuthHandler(user, pass string) ChainHandler

func (ChainHandler) Chain

func (ch ChainHandler) Chain(next ChainHandler) ChainHandler

func (ChainHandler) Finally

func (ch ChainHandler) Finally(last func(w http.ResponseWriter, req *http.Request)) func(w http.ResponseWriter, req *http.Request)

type Handler

type Handler interface {
	QueryHandler | BodyHandler | RequestHandler
}

type QueryHandler

type QueryHandler func(*url.Values) (int, string, func(io.Writer))

type Request

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

func Get

func Get(url string) *Request

func Post

func Post(url string) *Request

func (*Request) Do

func (r *Request) Do() (*http.Response, error)

func (*Request) WithBody

func (r *Request) WithBody(body any) *Request

func (*Request) WithFormValue

func (r *Request) WithFormValue(key string, value string) *Request

func (*Request) WithHeader

func (r *Request) WithHeader(key, value string) *Request

func (*Request) WithHeaders

func (r *Request) WithHeaders(headers map[string]string) *Request

type RequestHandler

type RequestHandler func(req *http.Request) (int, string, func(io.Writer))

func File

func File(mime string, f io.Reader) RequestHandler

func Html

func Html(str string) RequestHandler

type ResponseBuilder

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

func ErrBadRequest

func ErrBadRequest(body any) *ResponseBuilder

func ErrInternal

func ErrInternal(body any) *ResponseBuilder

func ErrNotFound

func ErrNotFound(body any) *ResponseBuilder

func NewResponse

func NewResponse() *ResponseBuilder

func Ok

func Ok(body any) *ResponseBuilder

func (*ResponseBuilder) AsHtml

func (rb *ResponseBuilder) AsHtml() (int, string, func(io.Writer))

func (*ResponseBuilder) AsJson

func (rb *ResponseBuilder) AsJson() (int, string, func(io.Writer))

func (*ResponseBuilder) AsTextPlain

func (rb *ResponseBuilder) AsTextPlain() (int, string, func(io.Writer))

func (*ResponseBuilder) Body

func (rb *ResponseBuilder) Body(body any) *ResponseBuilder

func (*ResponseBuilder) Build

func (rb *ResponseBuilder) Build() (int, string, func(io.Writer))

func (*ResponseBuilder) ContentType

func (rb *ResponseBuilder) ContentType(contentType string) *ResponseBuilder

func (*ResponseBuilder) Status

func (rb *ResponseBuilder) Status(status int) *ResponseBuilder

Jump to

Keyboard shortcuts

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