header

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Accept                          = "Accept"
	AcceptCharset                   = "Accept-Charset"
	AccessControlAllowCredentials   = "Access-Control-Allow-Credentials"
	AccessControlAllowHeaders       = "Access-Control-Allow-Headers"
	AccessControlAllowMethods       = "Access-Control-Allow-Methods"
	AccessControlAllowOrigin        = "Access-Control-Allow-Origin"
	AccessControlExposeHeaders      = "Access-Control-Expose-Headers"
	AccessControlMaxAge             = "Access-Control-Max-Age"
	AccessControlRequestHeaders     = "Access-Control-Request-Headers"
	AccessControlRequestMethod      = "Access-Control-Request-Method"
	AcceptEncoding                  = "Accept-Encoding"
	AcceptLanguage                  = "Accept-Language"
	AcceptRanges                    = "Accept-Ranges"
	Allow                           = "Allow"
	Age                             = "Age"
	AltSvc                          = "Alt-Svc"
	Authorization                   = "Authorization"
	CacheControl                    = "Cache-Control"
	Cc                              = "Cc"
	ClearSiteData                   = "Clear-Site-Data"
	Connection                      = "Connection"
	ContentType                     = "Content-Type"
	ContentLocation                 = "Content-Location"
	ContentRange                    = "Content-Range"
	ContentID                       = "Content-Id"
	ContentDisposition              = "Content-Disposition"
	ContentLanguage                 = "Content-Language"
	ContentLength                   = "Content-Length"
	ContentEncoding                 = "Content-Encoding"
	ContentTransferEncoding         = "Content-Transfer-Encoding"
	Cookie                          = "Cookie"
	CrossOriginResourcePolicy       = "Cross-Origin-Resource-Policy"
	ContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
	ContentSecurityPolicy           = "Content-Security-Policy"
	DNS                             = "DNS"
	Date                            = "Date"
	DNT                             = "DNT"
	Digest                          = "Digest"
	DkimSignature                   = "Dkim-Signature"
	Etag                            = "Etag"
	EarlyData                       = "Early-Data"
	Expect                          = "Expect"
	ExpectCT                        = "Expect-CT"
	Expires                         = "Expires"
	FeaturePolicy                   = "Feature-Policy"
	From                            = "From"
	Forwarded                       = "Forwarded"
	Host                            = "Host"
	IfUnmodifiedSince               = "If-Unmodified-Since"
	IfModifiedSince                 = "If-Modified-Since"
	IfMatch                         = "If-Match"
	IfRange                         = "If-Range"
	IfNoneMatch                     = "If-None-Match"
	InReplyTo                       = "In-Reply-To"
	KeepAlive                       = "Keep-Alive"
	LargeAllocation                 = "Large-Allocation"
	LastModified                    = "Last-Modified"
	Location                        = "Location"
	MessageID                       = "Message-Id"
	MimeVersion                     = "Mime-Version"
	Origin                          = "Origin"
	PublicKeyPinsReportOnly         = "Public-Key-Pins-Report-Only"
	PublicKeyPins                   = "Public-Key-Pins"
	ProxyAuthorization              = "Proxy-Authorization"
	ProxyAuthenticate               = "Proxy-Authenticate"
	Pragma                          = "Pragma"
	Range                           = "Range"
	Referer                         = "Referer"
	RetryAfter                      = "Retry-After"
	ReferrerPolicy                  = "Referrer-Policy"
	Received                        = "Received"
	ReturnPath                      = "Return-Path"
	SaveData                        = "Save-Data"
	Server                          = "Server"
	SecWebSocketAccept              = "Sec-WebSocket-Accept"
	ServerTiming                    = "Server-Timing"
	SetCookie                       = "Set-Cookie"
	Subject                         = "Subject"
	StrictTransportSecurity         = "Strict-Transport-Security"
	SourceMap                       = "SourceMap"
	TE                              = "TE"
	TimingAllowOrigin               = "Timing-Allow-Origin"
	Tk                              = "Tk"
	Trailer                         = "Trailer"
	TransferEncoding                = "Transfer-Encoding"
	To                              = "To"
	UserAgent                       = "User-Agent"
	UpgradeInsecureRequests         = "Upgrade-Insecure-Requests"
	Via                             = "Via"
	Vary                            = "Vary"
	WWWAuthenticate                 = "WWW-Authenticate"
	WantDigest                      = "Want-Digest"
	Warning                         = "Warning"
	ForwardedHost                   = "X-Forwarded-Host"
	ForwardedProto                  = "X-Forwarded-Proto"
	FrameOptions                    = "X-Frame-Options"
	XSSProtection                   = "X-XSS-Protection"
	ContentTypeOptions              = "X-Content-Type-Options"
	DNSPrefetchControl              = "X-DNS-Prefetch-Control"
	PoweredBy                       = "X-Powered-By"
	Imforwards                      = "X-Imforwards"
	RequestID                       = "X-Request-Id"
	ForwardedFor                    = "X-Forwarded-For"
	RealIP                          = "X-Real-Ip"
	AppEngineRemoteAddr             = "X-Appengine-Remote-Addr"
)

请求头常量 see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

View Source
const (
	ContentTypeJSON              = "application/json"
	ContentTypeForm              = "application/x-www-form-urlencoded"
	ContentTypeText              = "text/plain"
	ContentTypeXML               = "application/xml"
	ContentTypeStream            = "application/octet-stream"
	ContentTypeHTML              = "text/html"
	ContentTypeXML2              = "text/xml"
	ContentTypePlain             = "text/plain"
	ContentTypeMultipartPOSTForm = "multipart/form-data"
	ContentTypePROTOBUF          = "application/x-protobuf"
	ContentTypeMSGPACK           = "application/x-msgpack"
	ContentTypeMSGPACK2          = "application/msgpack"
)
View Source
const (
	SplitSepBlankSpace = " "
	SplitSepComma      = ","
	SplitSepSemicolon  = ";"
)

请求头分割字符

Variables

This section is empty.

Functions

func AddRequestHeader

func AddRequestHeader(r *http.Request, key string, values ...string) *http.Request

AddRequestHeader 添加指定请求头到 r

func AddRequestHeaderIf

func AddRequestHeaderIf(ensure bool, r *http.Request, key string, values ...string) *http.Request

AddRequestHeaderIf 添加指定请求头到 r,仅当 ensure 为 true 时生效

func AddRequestHeaders

func AddRequestHeaders(r *http.Request, headers map[string]string) *http.Request

AddRequestHeaders 添加指定请求头到 r

func AddRequestHeadersIf

func AddRequestHeadersIf(ensure bool, r *http.Request, headers map[string]string) *http.Request

AddRequestHeadersIf 添加指定请求头到 r,仅当 ensure 为 true 时生效

func AddResponseHeader

func AddResponseHeader(w http.ResponseWriter, key string, values ...string) http.ResponseWriter

AddResponseHeader 将指定响应头添加到 w 中

func AddResponseHeaderIf

func AddResponseHeaderIf(ensure bool, w http.ResponseWriter, key string, values ...string) http.ResponseWriter

AddResponseHeaderIf 将指定响应头添加到 w 中,仅当 ensure 为 true 时生效

func AddResponseHeaders

func AddResponseHeaders(w http.ResponseWriter, headers map[string]string) http.ResponseWriter

AddResponseHeaders 将指定响应头添加到 w 中

func AddResponseHeadersIf

func AddResponseHeadersIf(ensure bool, w http.ResponseWriter, headers map[string]string) http.ResponseWriter

AddResponseHeadersIf 将指定响应头添加到 w 中,仅当 ensure 为 true 时生效

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP 获取客户端 IP 地址 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. Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.

func GetHeader

func GetHeader(r *http.Request, header string) string

GetHeader 获取指定请求头

func GetHeaderRequestID

func GetHeaderRequestID(r *http.Request) string

GetHeaderRequestID 获取 RequestID

func GetHeaderValues

func GetHeaderValues(r *http.Request, header string) []string

GetHeaderValues 获取指定 key 的请求头集合

func GetResponseHeader

func GetResponseHeader(w http.ResponseWriter, header string) string

GetResponseHeader 获取指定响应头

func GetResponseHeaderValues

func GetResponseHeaderValues(w http.ResponseWriter, header string) []string

GetResponseHeaderValues 获取指定 key 响应头集合

func SetRequestHeader

func SetRequestHeader(r *http.Request, key, value string) *http.Request

SetRequestHeader 添加指定请求头

func SetRequestHeaderIf

func SetRequestHeaderIf(ensure bool, r *http.Request, key, value string) *http.Request

SetRequestHeaderIf 添加指定请求头,仅当 ensure 为 true 时生效

func SetRequestHeaderRequestID

func SetRequestHeaderRequestID(r *http.Request, id string) *http.Request

SetRequestHeaderRequestID 在 request 中添加 RequestID

func SetRequestHeaders

func SetRequestHeaders(r *http.Request, headers map[string]string) *http.Request

SetRequestHeaders 添加指定请求头

func SetRequestHeadersIf

func SetRequestHeadersIf(ensure bool, r *http.Request, headers map[string]string) *http.Request

SetRequestHeadersIf 添加指定请求头,仅当 ensure 为 true 时生效

func SetResponseHeader

func SetResponseHeader(w http.ResponseWriter, key, value string) http.ResponseWriter

SetResponseHeader 将指定请求头添加到响应中

func SetResponseHeaderIf

func SetResponseHeaderIf(ensure bool, w http.ResponseWriter, key, value string) http.ResponseWriter

SetResponseHeaderIf 将指定请求头添加到响应中,仅当 ensure 为 true 时生效

func SetResponseHeaderRequestID

func SetResponseHeaderRequestID(w http.ResponseWriter, id string) http.ResponseWriter

SetResponseHeaderRequestID 在 response 中添加 RequestID

func SetResponseHeaders

func SetResponseHeaders(w http.ResponseWriter, headers map[string]string) http.ResponseWriter

SetResponseHeaders 将指定请求头添加到响应中

func SetResponseHeadersIf

func SetResponseHeadersIf(ensure bool, w http.ResponseWriter, headers map[string]string) http.ResponseWriter

SetResponseHeadersIf 将指定请求头添加到响应中,仅当 ensure 为 true 时生效

func SplitHeader

func SplitHeader(r *http.Request, header string, splitSep string) []string

SplitHeader 分割指定请求头内容

Types

This section is empty.

Jump to

Keyboard shortcuts

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