mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-01 15:16:50 +00:00
chore: add some comments for using the new net/http API
This commit is contained in:
1 parent
98aa7e63c2
commit
faa58f27fc
10 files changed
+54
-1
No files matched your search
@@ -163,7 +163,11 @@ func NewMasque(option MasqueOption) (*Masque, error) {
|
||||
|
||||
if option.Network == "h2" {
|
||||
tlsConfig.NextProtos = []string{"h2"}
|
||||
// use h2c mode to disallow the net/http fallback to http1.1 when server returns a not h2 ALPN
|
||||
// use h2c mode to disallow the net/http fallback to http1.1 when the server returns a not h2 ALPN
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
outbound.h2Transport = &http.Transport{
|
||||
|
||||
@@ -134,6 +134,10 @@ func GetRealityConn(ctx context.Context, conn net.Conn, fingerprint UClientHello
|
||||
func realityClientFallback(uConn net.Conn, serverName string, fingerprint utls.ClientHelloID) {
|
||||
defer uConn.Close()
|
||||
// use h2c mode to disallow the net/http fallback to http1.1
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
client := http.Client{
|
||||
|
||||
@@ -151,6 +151,12 @@ func New(config LC.VlessServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
})
|
||||
httpServer.Protocols.SetHTTP2(true)
|
||||
// SetUnencryptedHTTP2 to ensure we can work in plain http2 and some tls conn is not *tls.Conn (like *reality.Conn)
|
||||
//
|
||||
// Enable HTTP/2 support unconditionally on the server.
|
||||
//
|
||||
// Note that this usage is limited to our own net/http fork
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by the Listener.
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
||||
tlsConfig.NextProtos = append([]string{"h2"}, tlsConfig.NextProtos...) // h2 must before http/1.1
|
||||
}
|
||||
@@ -197,6 +203,12 @@ func New(config LC.VlessServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
httpServer.Protocols.SetHTTP1(true)
|
||||
httpServer.Protocols.SetHTTP2(true)
|
||||
// SetUnencryptedHTTP2 to ensure we can work in plain http2 and some tls conn is not *tls.Conn (like *reality.Conn)
|
||||
//
|
||||
// Enable HTTP/2 support unconditionally on the server.
|
||||
//
|
||||
// Note that this usage is limited to our own net/http fork
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by the Listener.
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
||||
if !slices.Contains(tlsConfig.NextProtos, "http/1.1") {
|
||||
tlsConfig.NextProtos = append([]string{"http/1.1"}, tlsConfig.NextProtos...)
|
||||
|
||||
@@ -149,6 +149,12 @@ func New(config LC.VmessServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
})
|
||||
httpServer.Protocols.SetHTTP2(true)
|
||||
// SetUnencryptedHTTP2 to ensure we can work in plain http2 and some tls conn is not *tls.Conn (like *reality.Conn)
|
||||
//
|
||||
// Enable HTTP/2 support unconditionally on the server.
|
||||
//
|
||||
// Note that this usage is limited to our own net/http fork
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by the Listener.
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
||||
tlsConfig.NextProtos = append([]string{"h2"}, tlsConfig.NextProtos...) // h2 must before http/1.1
|
||||
}
|
||||
|
||||
@@ -146,6 +146,12 @@ func New(config LC.TrojanServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
})
|
||||
httpServer.Protocols.SetHTTP2(true)
|
||||
// SetUnencryptedHTTP2 to ensure we can work in plain http2 and some tls conn is not *tls.Conn (like *reality.Conn)
|
||||
//
|
||||
// Enable HTTP/2 support unconditionally on the server.
|
||||
//
|
||||
// Note that this usage is limited to our own net/http fork
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by the Listener.
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
httpServer.Protocols.SetUnencryptedHTTP2(true)
|
||||
tlsConfig.NextProtos = append([]string{"h2"}, tlsConfig.NextProtos...) // h2 must before http/1.1
|
||||
}
|
||||
|
||||
@@ -290,6 +290,10 @@ func NewTransport(dialFn DialFn, tlsConfig *vmess.TLSConfig, gunCfg *Config) *Tr
|
||||
}
|
||||
|
||||
// use h2c mode to disallow the net/http fallback to http1.1
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext,
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
transport := &http.Transport{
|
||||
|
||||
@@ -87,6 +87,10 @@ func NewClient(ctx context.Context, options ClientOptions) (client *Client, err
|
||||
|
||||
func (c *Client) h2RoundTripper(tlsConfig *vmess.TLSConfig) {
|
||||
// use h2c mode to disallow the net/http fallback to http1.1
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext,
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
c.roundTripper = &http.Transport{
|
||||
|
||||
@@ -74,6 +74,11 @@ func (s *Service) Start(tcpListener net.Listener, udpConn net.PacketConn, tlsCon
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetHTTP1(true)
|
||||
protocols.SetHTTP2(true)
|
||||
// Enable HTTP/2 support unconditionally on the server.
|
||||
//
|
||||
// Note that this usage is limited to our own net/http fork
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by the Listener.
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
s.httpServer = &http.Server{
|
||||
Handler: s,
|
||||
|
||||
@@ -101,6 +101,10 @@ func StreamH2Conn(ctx context.Context, conn net.Conn, cfg *H2Config) (_ net.Conn
|
||||
}
|
||||
|
||||
// use h2c mode to disallow the net/http fallback to http1.1
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext,
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
transport := &http.Transport{
|
||||
|
||||
@@ -203,6 +203,10 @@ func NewTransport(dialRaw DialRawFunc, wrapTLS WrapTLSFunc, dialQUIC DialQUICFun
|
||||
keepAlivePeriod = 0
|
||||
}
|
||||
// use h2c mode to disallow the net/http fallback to http1.1
|
||||
//
|
||||
// Note that this usage is only applicable to our own net/http fork.
|
||||
// The standard library also needs to mask the tls.Conn type for the conn returned by DialTLSContext,
|
||||
// see: https://github.com/golang/go/issues/79293#issuecomment-4426393534
|
||||
protocols := new(http.Protocols)
|
||||
protocols.SetUnencryptedHTTP2(true)
|
||||
return &http.Transport{
|
||||
|
||||
Reference in new issue
Block a user