force downgrade to http/1.1 because safari

This commit is contained in:
Brad Rydzewski 2017-09-19 15:30:31 -07:00
parent 4532110141
commit ae51e9d1b9

View file

@ -15,7 +15,6 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"github.com/lucas-clemente/quic-go/h2quic"
"golang.org/x/crypto/acme/autocert" "golang.org/x/crypto/acme/autocert"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -540,11 +539,16 @@ func server(c *cli.Context) error {
return http.ListenAndServe(":http", handler) return http.ListenAndServe(":http", handler)
}) })
g.Go(func() error { g.Go(func() error {
return http.ListenAndServeTLS( serve := &http.Server{
":https", Addr: ":https",
Handler: handler,
TLSConfig: &tls.Config{
NextProtos: []string{"http/1.1"}, // disable h2 because Safari :(
},
}
return serve.ListenAndServeTLS(
c.String("server-cert"), c.String("server-cert"),
c.String("server-key"), c.String("server-key"),
handler,
) )
}) })
return g.Wait() return g.Wait()
@ -569,42 +573,24 @@ func server(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
if c.Bool("quic") {
dir := cacheDir()
os.MkdirAll(dir, 0700)
manager := autocert.Manager{ dir := cacheDir()
Prompt: autocert.AcceptTOS, os.MkdirAll(dir, 0700)
HostPolicy: autocert.HostWhitelist(address.Host),
Cache: autocert.DirCache(dir),
}
httpServer := &http.Server{
Addr: ":443",
Handler: handler,
TLSConfig: &tls.Config{
GetCertificate: manager.GetCertificate,
NextProtos: []string{"h2", "http/1.1"},
},
}
quicServer := &h2quic.Server{
Server: httpServer,
}
quicServer.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { manager := autocert.Manager{
quicServer.SetQuicHeaders(w.Header()) Prompt: autocert.AcceptTOS,
handler.ServeHTTP(w, r) HostPolicy: autocert.HostWhitelist(address.Host),
}) Cache: autocert.DirCache(dir),
conn, err := net.ListenPacket("udp", ":443")
if err != nil {
return err
}
g.Go(func() error {
return quicServer.Serve(conn)
})
return http.Serve(manager.Listener(), quicServer.Handler)
} }
return http.Serve(autocert.NewListener(address.Host), handler) serve := &http.Server{
Addr: ":https",
Handler: handler,
TLSConfig: &tls.Config{
GetCertificate: manager.GetCertificate,
NextProtos: []string{"http/1.1"}, // disable h2 because Safari :(
},
}
return serve.ListenAndServeTLS("", "")
}) })
return g.Wait() return g.Wait()