Add health check support for http-based v2ray transport

This commit is contained in:
世界
2023-03-11 15:49:02 +08:00
parent bdc620dab1
commit 6af9c2b3ca
7 changed files with 45 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/tls"
@@ -45,6 +46,8 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
} else {
tlsConfig.SetNextProtos([]string{http2.NextProtoTLS})
transport = &http2.Transport{
ReadIdleTimeout: time.Duration(options.IdleTimeout),
PingTimeout: time.Duration(options.PingTimeout),
DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.STDConfig) (net.Conn, error) {
conn, err := dialer.DialContext(ctx, network, M.ParseSocksaddr(addr))
if err != nil {

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"os"
"strings"
"time"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/tls"
@@ -46,11 +47,13 @@ func NewServer(ctx context.Context, options option.V2RayHTTPOptions, tlsConfig t
ctx: ctx,
tlsConfig: tlsConfig,
handler: handler,
h2Server: new(http2.Server),
host: options.Host,
path: options.Path,
method: options.Method,
headers: make(http.Header),
h2Server: &http2.Server{
IdleTimeout: time.Duration(options.IdleTimeout),
},
host: options.Host,
path: options.Path,
method: options.Method,
headers: make(http.Header),
}
if server.method == "" {
server.method = "PUT"