}
w.imported[name] = &importing
+ root := w.root
+ if strings.HasPrefix(name, "golang.org/x/") {
+ root = filepath.Join(root, "vendor")
+ }
+
// Determine package files.
- dir := filepath.Join(w.root, filepath.FromSlash(name))
+ dir := filepath.Join(root, filepath.FromSlash(name))
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
- log.Fatalf("no source in tree for package %q", pkg)
+ log.Fatalf("no source in tree for import %q: %v", name, err)
}
context := w.context
"L4", "NET", "OS",
"compress/gzip", "crypto/tls", "mime/multipart", "runtime/debug",
"net/http/internal",
+ "golang.org/x/net/http2/hpack",
},
"net/http/internal": {"L4"},
})
}
+func TestAutomaticHTTP2(t *testing.T) {
+ ln, err := net.Listen("tcp", ":0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ln.Close() // immediately (not a defer!)
+ var s Server
+ if err := s.Serve(ln); err == nil {
+ t.Fatal("expected an error")
+ }
+ on := s.TLSNextProto["h2"] != nil
+ if !on {
+ t.Errorf("http2 wasn't automatically enabled")
+ }
+}
+
type serverExpectTest struct {
contentLength int // of request body
chunked bool
// standard logger.
ErrorLog *log.Logger
- disableKeepAlives int32 // accessed atomically.
+ disableKeepAlives int32 // accessed atomically.
+ nextProtoOnce sync.Once // guards initialization of TLSNextProto in Serve
}
// A ConnState represents the state of a client connection to a server.
func (srv *Server) Serve(l net.Listener) error {
defer l.Close()
var tempDelay time.Duration // how long to sleep on accept failure
+ srv.nextProtoOnce.Do(srv.setNextProtoDefaults)
for {
rw, e := l.Accept()
if e != nil {
return srv.Serve(tlsListener)
}
+func (srv *Server) setNextProtoDefaults() {
+ // Enable HTTP/2 by default if the user hasn't otherwise
+ // configured their TLSNextProto map.
+ if srv.TLSNextProto == nil {
+ http2ConfigureServer(srv, nil)
+ }
+}
+
// TimeoutHandler returns a Handler that runs h with the given time limit.
//
// The new Handler calls h.ServeHTTP to handle each request, but if a