httpext

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Gzip     string = "gzip"
	Compress string = "compress"
	Deflate  string = "deflate"
	Br       string = "br"
	Identity string = "identity"
	Any      string = "*"
)

Accept-Encoding values

View Source
const (
	UTF8     string = "utf-8"
	ISO88591 string = "iso-8859-1"
)

Charset values

View Source
const (
	Age                           string = "Age"
	AltSCV                        string = "Alt-Svc"
	Accept                        string = "Accept"
	AcceptCharset                 string = "Accept-Charset"
	AcceptPatch                   string = "Accept-Patch"
	AcceptRanges                  string = "Accept-Ranges"
	AcceptedLanguage              string = "Accept-Language"
	AcceptEncoding                string = "Accept-Encoding"
	Authorization                 string = "Authorization"
	CrossOriginResourcePolicy     string = "Cross-Origin-Resource-Policy"
	CacheControl                  string = "Cache-Control"
	Connection                    string = "Connection"
	ContentDisposition            string = "Content-Disposition"
	ContentEncoding               string = "Content-Encoding"
	ContentLength                 string = "Content-Length"
	ContentType                   string = "Content-Type"
	ContentLanguage               string = "Content-Language"
	ContentLocation               string = "Content-Location"
	ContentRange                  string = "Content-Range"
	Date                          string = "Date"
	DeltaBase                     string = "Delta-Base"
	ETag                          string = "ETag"
	Expires                       string = "Expires"
	Host                          string = "Host"
	IM                            string = "IM"
	IfMatch                       string = "If-Match"
	IfModifiedSince               string = "If-Modified-Since"
	IfNoneMatch                   string = "If-None-Match"
	IfRange                       string = "If-Range"
	IfUnmodifiedSince             string = "If-Unmodified-Since"
	KeepAlive                     string = "Keep-Alive"
	LastModified                  string = "Last-Modified"
	Link                          string = "Link"
	Pragma                        string = "Pragma"
	ProxyAuthenticate             string = "Proxy-Authenticate"
	ProxyAuthorization            string = "Proxy-Authorization"
	PublicKeyPins                 string = "Public-Key-Pins"
	RetryAfter                    string = "Retry-After"
	Referer                       string = "Referer"
	Server                        string = "Server"
	SetCookie                     string = "Set-Cookie"
	StrictTransportSecurity       string = "Strict-Transport-Security"
	Trailer                       string = "Trailer"
	TK                            string = "Tk"
	TransferEncoding              string = "Transfer-Encoding"
	Location                      string = "Location"
	Upgrade                       string = "Upgrade"
	Vary                          string = "Vary"
	Via                           string = "Via"
	Warning                       string = "Warning"
	WWWAuthenticate               string = "WWW-Authenticate"
	XForwardedFor                 string = "X-Forwarded-For"
	XForwardedHost                string = "X-Forwarded-Host"
	XForwardedProto               string = "X-Forwarded-Proto"
	XRealIP                       string = "X-Real-Ip"
	XContentTypeOptions           string = "X-Content-Type-Options"
	XFrameOptions                 string = "X-Frame-Options"
	XXSSProtection                string = "X-XSS-Protection"
	XDNSPrefetchControl           string = "X-DNS-Prefetch-Control"
	Allow                         string = "Allow"
	Origin                        string = "Origin"
	AccessControlAllowOrigin      string = "Access-Control-Allow-Origin"
	AccessControlAllowCredentials string = "Access-Control-Allow-Credentials"
	AccessControlAllowHeaders     string = "Access-Control-Allow-Headers"
	AccessControlAllowMethods     string = "Access-Control-Allow-Methods"
	AccessControlExposeHeaders    string = "Access-Control-Expose-Headers"
	AccessControlMaxAge           string = "Access-Control-Max-Age"
	AccessControlRequestHeaders   string = "Access-Control-Request-Headers"
	AccessControlRequestMethod    string = "Access-Control-Request-Method"
	TimingAllowOrigin             string = "Timing-Allow-Origin"
	UserAgent                     string = "User-Agent"
)

HTTP Header keys

View Source
const (
	ApplicationJSON       string = "application/json" + charsetUTF8
	ApplicationJavaScript string = "application/javascript"
	ApplicationXML        string = "application/xml" + charsetUTF8
	ApplicationForm       string = "application/x-www-form-urlencoded"
	ApplicationProtobuf   string = "application/protobuf"
	ApplicationMsgpack    string = "application/msgpack"
	ApplicationWasm       string = "application/wasm"
	ApplicationPDF        string = "application/pdf"
	TextHTML              string = "text/html" + charsetUTF8
	TextPlain             string = "text/plain" + charsetUTF8
	TextMarkdown          string = "text/markdown" + charsetUTF8
	TextCSS               string = "text/css" + charsetUTF8
	ImagePNG              string = "image/png"
	ImageGIF              string = "image/gif"
	ImageSVG              string = "image/svg+xml"
	ImageJPEG             string = "image/jpeg"
	MultipartForm         string = "multipart/form-data"
	OctetStream           string = "application/octet-stream"
)

Mime Type values for the Content-Type HTTP header

View Source
const (
	// QualityValueFormat is a format string helper for Quality Values
	QualityValueFormat = "%s;q=%1.3g"
)

Variables

This section is empty.

Functions

func AcceptedLanguages

func AcceptedLanguages(r *http.Request) (languages []string)

AcceptedLanguages returns an array of accepted languages denoted by the Accept-Language header sent by the browser

func Attachment

func Attachment(w http.ResponseWriter, r io.Reader, filename string) (err error)

Attachment is a helper method for returning an attachement file to be downloaded, if you with to open inline see function Inline

func ClientIP

func ClientIP(r *http.Request) (clientIP string)

ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.

func Decode

func Decode(r *http.Request, qp QueryParamsOption, maxMemory int64, v interface{}) (err error)

Decode takes the request and attempts to discover it's content type via the http headers and then decode the request body into the provided struct. Example if header was "application/json" would decode using json.NewDecoder(ioext.LimitReader(r.Body, maxMemory)).Decode(v).

This default to parsing query params if includeQueryParams=true and no other content type matches.

NOTE: when includeQueryParams=true query params will be parsed and included eg. route /user?test=true 'test' is added to parsed XML and replaces any value that may have been present

func DecodeForm

func DecodeForm(r *http.Request, qp QueryParamsOption, v interface{}) (err error)

DecodeForm parses the requests form data into the provided struct.

The Content-Type and http method are not checked.

NOTE: when QueryParamsOption=QueryParams the query params will be parsed and included eg. route /user?test=true 'test' is added to parsed Form.

func DecodeJSON

func DecodeJSON(r *http.Request, qp QueryParamsOption, maxMemory int64, v interface{}) (err error)

DecodeJSON decodes the request body into the provided struct and limits the request size via an ioext.LimitReader using the maxMemory param.

The Content-Type e.g. "application/json" and http method are not checked.

NOTE: when includeQueryParams=true query params will be parsed and included eg. route /user?test=true 'test' is added to parsed JSON and replaces any value that may have been present

func DecodeMultipartForm

func DecodeMultipartForm(r *http.Request, qp QueryParamsOption, maxMemory int64, v interface{}) (err error)

DecodeMultipartForm parses the requests form data into the provided struct.

The Content-Type and http method are not checked.

NOTE: when includeQueryParams=true query params will be parsed and included eg. route /user?test=true 'test' is added to parsed MultipartForm.

func DecodeQueryParams

func DecodeQueryParams(r *http.Request, v interface{}) (err error)

DecodeQueryParams takes the URL Query params flag.

func DecodeXML

func DecodeXML(r *http.Request, qp QueryParamsOption, maxMemory int64, v interface{}) (err error)

DecodeXML decodes the request body into the provided struct and limits the request size via an ioext.LimitReader using the maxMemory param.

The Content-Type e.g. "application/xml" and http method are not checked.

NOTE: when includeQueryParams=true query params will be parsed and included eg. route /user?test=true 'test' is added to parsed XML and replaces any value that may have been present

func Inline

func Inline(w http.ResponseWriter, r io.Reader, filename string) (err error)

Inline is a helper method for returning a file inline to be rendered/opened by the browser

func JSON

func JSON(w http.ResponseWriter, status int, i interface{}) error

JSON marshals provided interface + returns JSON + status code

func JSONBytes

func JSONBytes(w http.ResponseWriter, status int, b []byte) (err error)

JSONBytes returns provided JSON response with status code

func JSONP

func JSONP(w http.ResponseWriter, status int, i interface{}, callback string) error

JSONP sends a JSONP response with status code and uses `callback` to construct the JSONP payload.

func QualityValue

func QualityValue(v string, qv float32) string

QualityValue accepts a value to add/concatenate a quality value to and the quality value itself.

func XML

func XML(w http.ResponseWriter, status int, i interface{}) error

XML marshals provided interface + returns XML + status code

func XMLBytes

func XMLBytes(w http.ResponseWriter, status int, b []byte) (err error)

XMLBytes returns provided XML response with status code

Types

type FormDecoder

type FormDecoder interface {
	Decode(interface{}, url.Values) error
}

FormDecoder is the type used for decoding a form for use

var (
	// DefaultFormDecoder of this package, which is configurable
	DefaultFormDecoder FormDecoder = form.NewDecoder()
)

type QueryParamsOption

type QueryParamsOption uint8

QueryParamsOption represents the options for including query parameters during Decode helper functions

const (
	QueryParams QueryParamsOption = iota
	NoQueryParams
)

Jump to

Keyboard shortcuts

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