第 7 期 2018-05-24 線下活動 - Go 標準包閱讀

mai_yang發表於2020-02-13

文章來自於:https://reading.developerlearning.cn/reading/7-2018-05-24-net-http-part1/

視訊回看

Go 標準包閱讀

Go 版本:go 1.10.1

net/http

  • server.go

問題

  1. Next Protocol Negotiation = NPN
  2. Expect 100 Continue support

見參考資料

  1. header 提到了:Expect 和 host
  2. 判斷了 header 裡面的 HOST,但是後面又刪除,為什麼?

server.go#L980

delete(req.Header, "Host")
  1. 判斷是否支援 HTTP2 (isH2Upgrade)
// isH2Upgrade reports whether r represents the http2 "client preface"
// magic string.
func (r *Request) isH2Upgrade() bool {
    return r.Method == "PRI" && len(r.Header) == 0 && r.URL.Path == "*" && r.Proto == "HTTP/2.0"
}
呼叫ProtoAtLeast(1, 1)
...
// ProtoAtLeast reports whether the HTTP protocol used
// in the request is at least major.minor.
func (r *Request) ProtoAtLeast(major, minor int) bool {
    return r.ProtoMajor > major ||
        r.ProtoMajor == major && r.ProtoMinor >= minor
}

延伸閱讀

  1. https://github.com/golang/go/issues/22128
  2. https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-26#section-6.2.1
  3. https://www.cnblogs.com/tekkaman/archive/2013/04/03/2997781.html
  4. https://benramsey.com/blog/2008/04/http-status-100-continue/
  5. http://www.ituring.com.cn/article/130844

更多原創文章乾貨分享,請關注公眾號

更多原創文章乾貨分享,請關注公眾號
  • 第 7 期 2018-05-24 線下活動 - Go 標準包閱讀
  • 加微信實戰群請加微信(註明:實戰群):gocnio

相關文章