第 7 期 2018-05-24 线下活动 - Go 标准包 net/http 源码阅读(一)

视频回看

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. net/http: Several 100-continue · Issue #22128 · golang/go · GitHub
  2. draft-ietf-httpbis-p2-semantics-26
  3. http之100-continue - Tekkaman - 博客园
  4. https://benramsey.com/blog/2008/04/http-status-100-continue/
  5. http://www.ituring.com.cn/article/130844