duanjianl183188
2015-01-09 19:18
浏览 40
已采纳

Go中的HTTP标头名称

I need to collect a bunch of http headers. The only way I found yet is *http.Request .Header.Get("%header name%") Is there any name conventions for %header name% ?
E.g. in PHP all keys are uppercased, words separated with underscore.

图片转代码服务由CSDN问答提供 功能建议

我需要收集一堆http标头。 我发现的唯一方法是* http.Request .Header.Get(“%header name%”) %header name%是否有任何名称约定?
例如在PHP中,所有键都是大写的,单词之间用下划线分隔。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandong7980 2015-01-09 19:31
    已采纳

    The keys in a header are in canonical format.

    The Header methods canonicalize the the key for you.

    If the application accesses the header map directly, then the application is responsible for ensuring that the key is in canonical format.

    Some examples of header names in canonical format are:

    Content-Length
    Etag
    

    You can find all headers using range:

    for name, values := range req.Header {
         fmt.Printf("%s: %v
    ", name, values)
    }
    
    点赞 打赏 评论

相关推荐 更多相似问题