Use net.http by default
This commit is contained in:
parent
bc9af1d613
commit
7c38374d99
4
go.mod
4
go.mod
|
@ -20,8 +20,8 @@ require (
|
|||
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
||||
github.com/marten-seemann/qpack v0.2.1 // indirect
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
|
||||
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
|
||||
github.com/minio/sha256-simd v1.0.0 // indirect
|
||||
github.com/mr-tron/base58 v1.2.0 // indirect
|
||||
|
|
6
go.sum
6
go.sum
|
@ -99,10 +99,12 @@ github.com/marten-seemann/qpack v0.2.1 h1:jvTsT/HpCn2UZJdP+UUB53FfUUgeOyG5K1ns0O
|
|||
github.com/marten-seemann/qpack v0.2.1/go.mod h1:F7Gl5L1jIgN1D11ucXefiuJS9UMVP2opoCp2jDKb7wc=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.5 h1:o9JrYPPco/Nukd/HpOHMHZoBDXQqoNtUCmny98/1uqQ=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.5/go.mod h1:gNpI2Ol+lRS3WwSOtIUUtRwZEQMXjYK+dQSBFbethAk=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.1 h1:DQjHPq+aOzUeh9/lixAGunn6rIOQyWChPSI4+hgW7jc=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.1/go.mod h1:C2ekUKcDdz9SDWxec1N/MvcXBpaX9l3Nx67XaR84L5s=
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.1 h1:qp7p7XXUFL7fpBvSS1sWD+uSqPvzNQK43DH+/qEkj0Y=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.2 h1:JADBlm0LYiVbuSySCHeY863dNkcpMmDR7s0bLKJeYlQ=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.2/go.mod h1:C2ekUKcDdz9SDWxec1N/MvcXBpaX9l3Nx67XaR84L5s=
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.1/go.mod h1:mJttiymBAByA49mhlNZZGrH5u1uXYZJ+RW28Py7f4m4=
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.2 h1:JH6jmzbduz0ITVQ7ShevK10Av5+jBEKAHMntXmIV7kM=
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.2/go.mod h1:mJttiymBAByA49mhlNZZGrH5u1uXYZJ+RW28Py7f4m4=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
type Server struct {
|
||||
ListenAddress string
|
||||
TLSConfig *tlsutils.Configuration
|
||||
UseFastHTTP bool
|
||||
EnableHTTP2 bool
|
||||
FastHTTPRequestServer FastHTTPRequestServer
|
||||
NetHTTPRequestServer NetHTTPRequestServer
|
||||
|
@ -77,48 +78,85 @@ func (server *Server) Serve() {
|
|||
server.AddExtraHeader("Connection", "close")
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if server.UseFastHTTP {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
handler := func(ctx *fasthttp.RequestCtx) RequestContext {
|
||||
return NewRequestContextFromFastHttp(server, ctx)
|
||||
}
|
||||
handler := func(ctx *fasthttp.RequestCtx) RequestContext {
|
||||
return NewRequestContextFromFastHttp(server, ctx)
|
||||
}
|
||||
|
||||
if server.FastHTTPRequestServer != nil {
|
||||
handler = server.FastHTTPRequestServer
|
||||
}
|
||||
if server.FastHTTPRequestServer != nil {
|
||||
handler = server.FastHTTPRequestServer
|
||||
}
|
||||
|
||||
s := &fasthttp.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
IdleTimeout: 15 * time.Second,
|
||||
Handler: func(ctx *fasthttp.RequestCtx) {
|
||||
server.Handler(handler(ctx))
|
||||
},
|
||||
NoDefaultServerHeader: true,
|
||||
NoDefaultDate: true,
|
||||
DisableKeepalive: !server.EnableHTTP2,
|
||||
TCPKeepalive: server.EnableHTTP2,
|
||||
TLSConfig: server.TLSConfig.Config,
|
||||
}
|
||||
s := &fasthttp.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
IdleTimeout: 15 * time.Second,
|
||||
Handler: func(ctx *fasthttp.RequestCtx) {
|
||||
server.Handler(handler(ctx))
|
||||
},
|
||||
NoDefaultServerHeader: true,
|
||||
NoDefaultDate: true,
|
||||
DisableKeepalive: !server.EnableHTTP2,
|
||||
TCPKeepalive: server.EnableHTTP2,
|
||||
TLSConfig: server.TLSConfig.Config,
|
||||
}
|
||||
|
||||
if server.EnableHTTP2 {
|
||||
http2.ConfigureServer(s, http2.ServerConfig{
|
||||
Debug: server.Debug,
|
||||
})
|
||||
}
|
||||
if server.EnableHTTP2 {
|
||||
http2.ConfigureServer(s, http2.ServerConfig{
|
||||
Debug: server.Debug,
|
||||
})
|
||||
}
|
||||
|
||||
log.Printf("[Server] Serving TCP on %s", server.ListenAddress)
|
||||
ln, err := net.Listen("tcp", server.ListenAddress)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
err = s.Serve(tls.NewListener(ln, s.TLSConfig.Clone()))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}()
|
||||
log.Printf("[Server] Serving TCP on %s", server.ListenAddress)
|
||||
ln, err := net.Listen("tcp", server.ListenAddress)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
err = s.Serve(tls.NewListener(ln, s.TLSConfig.Clone()))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
handler := func(w http.ResponseWriter, r *http.Request) RequestContext {
|
||||
return NewRequestContextFromHttp(server, w, r)
|
||||
}
|
||||
|
||||
if server.NetHTTPRequestServer != nil {
|
||||
handler = server.NetHTTPRequestServer
|
||||
}
|
||||
|
||||
s := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
IdleTimeout: 15 * time.Second,
|
||||
Addr: server.ListenAddress,
|
||||
TLSConfig: server.TLSConfig.QUICConfig,
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
server.Handler(handler(w, r))
|
||||
}),
|
||||
}
|
||||
s.SetKeepAlivesEnabled(!server.EnableHTTP2)
|
||||
|
||||
log.Printf("[Server] Serving TCP on %s", server.ListenAddress)
|
||||
ln, err := net.Listen("tcp", server.ListenAddress)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
err = s.Serve(tls.NewListener(ln, s.TLSConfig.Clone()))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if server.EnableHTTP3 {
|
||||
wg.Add(1)
|
||||
|
|
Loading…
Reference in a new issue