Documentation
¶
Overview ¶
Package qheader 与报头相关的处理方法
Index ¶
- Constants
- func BuildContentType(mt, charset string) string
- func CharsetIsNop(enc encoding.Encoding) bool
- func ClientIP(r *http.Request) string
- func InitETag(w http.ResponseWriter, r *http.Request, etag string, weak bool) bool
- func ParseAcceptCharset(h string) (name string, enc encoding.Encoding)
- func ParseWithParam(header, param string) (mt, paramValue string)
- func PutQHeader(items *[]*Item)
- type Item
Constants ¶
const ( Identity = "identity" KeepAlive = "keep-alive" )
一些常用的报头值
Variables ¶
This section is empty.
Functions ¶
func BuildContentType ¶
func ParseAcceptCharset ¶
ParseAcceptCharset 根据 Accept-Charset 报头的内容获取其最值的字符集信息
传递 * 获取返回默认的字符集相关信息,即 utf-8 其它值则按值查找,或是在找不到时返回空值。
返回的 name 值可能会与 header 中指定的不一样,比如 gb_2312 会被转换成 gbk
func ParseWithParam ¶
ParseWithParam 分析带参数的报头
比如 content-type 可能带字符集的参数:content-type: application/json; charset=utf-8。 只返回主值以及指定名称的参数,其它忽略。
与 mime.ParseMediaType 最大的不同在于不会返回除 param 指定外的其它参数, 所以理论上性能也会更好一些,且也不局限于 RFC1521 规定的 content-type 报头, 对于 Accept 等,也可以分段解析。 param 可以为空,表示不需要解析任何参数。 paramValue 的返回值一律被转换为小写。
func PutQHeader ¶
func PutQHeader(items *[]*Item)
Types ¶
type Item ¶
Item 表示报头内容的单个元素内容
比如 zh-cmt;q=0.8, zh-cmn;q=1, 拆分成两个 Item 对象。
func ParseQHeader ¶
ParseQHeader 解析报头内容
排序方式如下:
Q 值大的靠前,如果 Q 值相同,则全名的比带通配符的靠前,*/* 最后,都是全名则按原来顺序返回。
header 表示报头的内容; any 表示通配符的值,只能是 */*、* 和空值,其它情况则 panic;