Documentation
¶
Index ¶
- Constants
- func AddRequestHeader(r *http.Request, key string, values ...string) *http.Request
- func AddRequestHeaderIf(ensure bool, r *http.Request, key string, values ...string) *http.Request
- func AddRequestHeaders(r *http.Request, headers map[string]string) *http.Request
- func AddRequestHeadersIf(ensure bool, r *http.Request, headers map[string]string) *http.Request
- func AddResponseHeader(w http.ResponseWriter, key string, values ...string) http.ResponseWriter
- func AddResponseHeaderIf(ensure bool, w http.ResponseWriter, key string, values ...string) http.ResponseWriter
- func AddResponseHeaders(w http.ResponseWriter, headers map[string]string) http.ResponseWriter
- func AddResponseHeadersIf(ensure bool, w http.ResponseWriter, headers map[string]string) http.ResponseWriter
- func GetClientIP(r *http.Request) string
- func GetHeader(r *http.Request, header string) string
- func GetHeaderRequestID(r *http.Request) string
- func GetHeaderValues(r *http.Request, header string) []string
- func GetResponseHeader(w http.ResponseWriter, header string) string
- func GetResponseHeaderValues(w http.ResponseWriter, header string) []string
- func SetRequestHeader(r *http.Request, key, value string) *http.Request
- func SetRequestHeaderIf(ensure bool, r *http.Request, key, value string) *http.Request
- func SetRequestHeaderRequestID(r *http.Request, id string) *http.Request
- func SetRequestHeaders(r *http.Request, headers map[string]string) *http.Request
- func SetRequestHeadersIf(ensure bool, r *http.Request, headers map[string]string) *http.Request
- func SetResponseHeader(w http.ResponseWriter, key, value string) http.ResponseWriter
- func SetResponseHeaderIf(ensure bool, w http.ResponseWriter, key, value string) http.ResponseWriter
- func SetResponseHeaderRequestID(w http.ResponseWriter, id string) http.ResponseWriter
- func SetResponseHeaders(w http.ResponseWriter, headers map[string]string) http.ResponseWriter
- func SetResponseHeadersIf(ensure bool, w http.ResponseWriter, headers map[string]string) http.ResponseWriter
- func SplitHeader(r *http.Request, header string, splitSep string) []string
Constants ¶
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
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" )
const ( SplitSepBlankSpace = " " SplitSepComma = "," SplitSepSemicolon = ";" )
请求头分割字符
Variables ¶
This section is empty.
Functions ¶
func AddRequestHeader ¶
AddRequestHeader 添加指定请求头到 r
func AddRequestHeaderIf ¶
AddRequestHeaderIf 添加指定请求头到 r,仅当 ensure 为 true 时生效
func AddRequestHeaders ¶
AddRequestHeaders 添加指定请求头到 r
func AddRequestHeadersIf ¶
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 ¶
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 GetHeaderRequestID ¶
GetHeaderRequestID 获取 RequestID
func GetHeaderValues ¶
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 ¶
SetRequestHeader 添加指定请求头
func SetRequestHeaderIf ¶
SetRequestHeaderIf 添加指定请求头,仅当 ensure 为 true 时生效
func SetRequestHeaderRequestID ¶
SetRequestHeaderRequestID 在 request 中添加 RequestID
func SetRequestHeaders ¶
SetRequestHeaders 添加指定请求头
func SetRequestHeadersIf ¶
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 时生效
Types ¶
This section is empty.