headerpkg

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

header

HTTP header 常量、Request ID 辅助函数和 header value 匹配。

基础用法

if headerpkg.ContainsValue(req.Header, "Connection", "upgrade") {
	// ...
}
req.Header.Set(headerpkg.ContentType, headerpkg.ContentTypeJSON)
headerpkg.SetRequestID(req.Header, "request-id")
headerpkg.SetContentType(req.Header, headerpkg.ContentTypeJSON)

注意事项

ContainsValue 支持逗号分隔 header,适合 WebSocket 和 HTTP 协议头判断。

验证

go test ./header

Documentation

Index

Constants

View Source
const (
	RequestID     = "x-kit-request-id"    // http请求id
	TraceID       = "x-kit-trace-id"      // trace-id
	InternalToken = "x-kit-authorization" // 内部令牌
	IsWebsocket   = "x-kit-websocket"     // http请求设置
	RemoteAddr    = "x-kit-remote-addr"   // 远程地址
	UserTerminal  = "x-kit-user-terminal" // 使用终端、平台

	// AuthorizationKey auth
	AuthorizationKey = "Authorization"

	// WebsocketConnection websocket
	WebsocketConnection = "Connection"
	WebsocketUpgrade    = "Upgrade"
	WebsocketSecVersion = "Sec-Websocket-Version"
	WebsocketSecKey     = "Sec-Websocket-Key"

	// ContentType header
	ContentType               = "Content-Type"
	ContentTypeJSON           = "application/json"
	ContentTypeJSONUtf8       = "application/json; charset=utf-8"
	ContentTypeProto          = "application/proto"
	ContentTypeProtobuf       = "application/x-protobuf"
	ContentTypeFormURLEncoded = "application/x-www-form-urlencoded"
	ContentTypeMultipartForm  = "multipart/form-data"

	// Accept header
	Accept         = "Accept"
	AcceptJSON     = "application/json"
	AcceptJSONUtf8 = "application/json; charset=utf-8"
	AcceptProto    = "application/proto"
	AcceptProtobuf = "application/x-protobuf"
)
View Source
const (
	// PlatformGoogleAppEngine When running on Google App Engine. Trust X-Appengine-Remote-Addr
	// for determining the client's IP
	PlatformGoogleAppEngine = "X-Appengine-Remote-Addr"
	// PlatformCloudflare When using Cloudflare's CDN. Trust CF-Connecting-IP for determining
	// the client's IP
	PlatformCloudflare = "CF-Connecting-IP"
)

Trusted platforms

Variables

This section is empty.

Functions

func ContainsValue

func ContainsValue(header http.Header, name string, value string) bool

ContainsValue . From websocket.tokenListContainsValue

func GetAuthorization

func GetAuthorization(header http.Header) string

GetAuthorization 获取 Authorization。

func GetContentType

func GetContentType(header http.Header) string

GetContentType 获取 Content-Type。

func GetIsWebsocket

func GetIsWebsocket(header http.Header) bool

GetIsWebsocket 获取是否websocket

func GetRequestID

func GetRequestID(header stdhttp.Header) string

GetRequestID 获取RequestID

func GetTraceID

func GetTraceID(header http.Header) string

GetTraceID 获取 TraceID。

func SetAuthorization

func SetAuthorization(header http.Header, authorization string)

SetAuthorization 设置 Authorization。

func SetContentType

func SetContentType(header http.Header, contentType string)

SetContentType 设置 Content-Type。

func SetIsWebsocket

func SetIsWebsocket(header http.Header)

SetIsWebsocket 设置是否websocket

func SetRequestID

func SetRequestID(header stdhttp.Header, requestID string)

SetRequestID 设置RequestID

func SetTraceID

func SetTraceID(header http.Header, traceID string)

SetTraceID 设置 TraceID。

Types

This section is empty.

Jump to

Keyboard shortcuts

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