Commit b336a971 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http2: initialize Server.IdleTimeout from http.Server as http1 does

This makes ConfigureServer initialize the http2 Server's IdleTimeout
from the http1 Server configuration, using the same rules as
IdleTimeout in Go 1.8: first use IdleTimeout if specified, else fall
back to the old ReadTimeout.

Updates golang/go#14204

Change-Id: I4dee971f8416ef0cbf99335a199c46355f9ab09d
Reviewed-on: https://go-review.googlesource.com/32230
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarTom Bergan <tombergan@google.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b626cca9
......@@ -24,3 +24,18 @@ func (w *responseWriter) Push(target string, opts *http.PushOptions) error {
}
return w.push(target, internalOpts)
}
func init() {
configServerFuncs = append(configServerFuncs, configureServer18)
}
func configureServer18(h1 *http.Server, h2 *Server) error {
if h2.IdleTimeout == 0 {
if h1.IdleTimeout != 0 {
h2.IdleTimeout = h1.IdleTimeout
} else {
h2.IdleTimeout = h1.ReadTimeout
}
}
return nil
}
......@@ -129,15 +129,27 @@ func (s *Server) maxConcurrentStreams() uint32 {
return defaultMaxStreams
}
// List of funcs for ConfigureServer to run. Both h1 and h2 are guaranteed
// to be non-nil.
var configServerFuncs []func(h1 *http.Server, h2 *Server) error
// ConfigureServer adds HTTP/2 support to a net/http Server.
//
// The configuration conf may be nil.
//
// ConfigureServer must be called before s begins serving.
func ConfigureServer(s *http.Server, conf *Server) error {
if s == nil {
panic("nil *http.Server")
}
if conf == nil {
conf = new(Server)
}
for _, fn := range configServerFuncs {
if err := fn(s, conf); err != nil {
return err
}
}
if s.TLSConfig == nil {
s.TLSConfig = new(tls.Config)
......@@ -1544,12 +1556,10 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
// The net/http package sets the read deadline from the
// http.Server.ReadTimeout during the TLS handshake, but then
// passes the connection off to us with the deadline already
// set. Disarm it here after the request headers are read, similar
// to how the http1 server works.
// Unlike http1, though, we never re-arm it yet, though.
// TODO(bradfitz): figure out golang.org/issue/14204
// (IdleTimeout) and how this relates. Maybe the default
// IdleTimeout is ReadTimeout.
// set. Disarm it here after the request headers are read,
// similar to how the http1 server works. Here it's
// technically more like the http1 Server's ReadHeaderTimeout
// (in Go 1.8), though. That's a more sane option anyway.
if sc.hs.ReadTimeout != 0 {
sc.conn.SetReadDeadline(time.Time{})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment