mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
Merge pull request #1793 from lucifer9/h2c
add server side h2c (http2 without TLS protection) support
This commit is contained in:
commit
aa3c337041
@ -16,6 +16,9 @@ import (
|
|||||||
"v2ray.com/core/common/signal/done"
|
"v2ray.com/core/common/signal/done"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
"v2ray.com/core/transport/internet/tls"
|
"v2ray.com/core/transport/internet/tls"
|
||||||
|
|
||||||
|
"golang.org/x/net/http2"
|
||||||
|
"golang.org/x/net/http2/h2c"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
@ -102,16 +105,23 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||||||
config: *httpSettings,
|
config: *httpSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var server *http.Server
|
||||||
config := tls.ConfigFromStreamSettings(streamSettings)
|
config := tls.ConfigFromStreamSettings(streamSettings)
|
||||||
if config == nil {
|
if config == nil {
|
||||||
return nil, newError("TLS must be enabled for http transport.").AtWarning()
|
h2s := &http2.Server{}
|
||||||
}
|
|
||||||
|
|
||||||
server := &http.Server{
|
server = &http.Server{
|
||||||
Addr: serial.Concat(address, ":", port),
|
Addr: serial.Concat(address, ":", port),
|
||||||
TLSConfig: config.GetTLSConfig(tls.WithNextProto("h2")),
|
Handler: h2c.NewHandler(listener, h2s),
|
||||||
Handler: listener,
|
ReadHeaderTimeout: time.Second * 4,
|
||||||
ReadHeaderTimeout: time.Second * 4,
|
}
|
||||||
|
} else {
|
||||||
|
server = &http.Server{
|
||||||
|
Addr: serial.Concat(address, ":", port),
|
||||||
|
TLSConfig: config.GetTLSConfig(tls.WithNextProto("h2")),
|
||||||
|
Handler: listener,
|
||||||
|
ReadHeaderTimeout: time.Second * 4,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.server = server
|
listener.server = server
|
||||||
@ -124,10 +134,16 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||||||
newError("failed to listen on", address, ":", port).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
newError("failed to listen on", address, ":", port).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if config == nil {
|
||||||
err = server.ServeTLS(tcpListener, "", "")
|
err = server.Serve(tcpListener)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
newError("stoping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
newError("stoping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = server.ServeTLS(tcpListener, "", "")
|
||||||
|
if err != nil {
|
||||||
|
newError("stoping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user