add compression flag option for http request

This commit is contained in:
ginuerzh
2024-11-02 20:41:23 +08:00
parent edb9a992e2
commit a12870e766
6 changed files with 23 additions and 11 deletions
+6 -1
View File
@@ -107,6 +107,7 @@ func (h *httpHandler) Init(md md.Metadata) error {
IdleConnTimeout: 30 * time.Second,
ResponseHeaderTimeout: h.md.readTimeout,
DisableKeepAlives: !h.md.keepalive,
DisableCompression: !h.md.compression,
}
return nil
@@ -627,7 +628,11 @@ func (h *httpHandler) proxyRoundTrip(ctx context.Context, rw io.ReadWriter, req
return
}
return resp.Close, nil
if resp.ContentLength >= 0 {
close = resp.Close
}
return
}
func (h *httpHandler) dial(ctx context.Context, network, addr string) (conn net.Conn, err error) {
+3 -4
View File
@@ -22,6 +22,7 @@ const (
type metadata struct {
readTimeout time.Duration
keepalive bool
compression bool
probeResistance *probeResistance
enableUDP bool
header http.Header
@@ -55,10 +56,8 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
h.md.header = hd
}
h.md.keepalive = true
if mdutil.IsExists(md, "http.keepalive", "keepalive") {
h.md.keepalive = mdutil.GetBool(md, "http.keepalive", "keepalive")
}
h.md.keepalive = mdutil.GetBool(md, "http.keepalive", "keepalive")
h.md.compression = mdutil.GetBool(md, "http.compression", "compression")
if pr := mdutil.GetString(md, "probeResist", "probe_resist"); pr != "" {
if ss := strings.SplitN(pr, ":", 2); len(ss) == 2 {
+1
View File
@@ -98,6 +98,7 @@ func (h *tunnelHandler) Init(md md.Metadata) (err error) {
IdleConnTimeout: 30 * time.Second,
ResponseHeaderTimeout: h.md.entryPointReadTimeout,
DisableKeepAlives: !h.md.entryPointKeepalive,
DisableCompression: !h.md.entryPointCompression,
}
for _, ro := range h.options.Recorders {
+3 -4
View File
@@ -26,6 +26,7 @@ type metadata struct {
entryPointID relay.TunnelID
entryPointProxyProtocol int
entryPointKeepalive bool
entryPointCompression bool
entryPointReadTimeout time.Duration
sniffingWebsocket bool
sniffingWebsocketSampleRate float64
@@ -45,10 +46,8 @@ func (h *tunnelHandler) parseMetadata(md mdata.Metadata) (err error) {
h.md.entryPointID = parseTunnelID(mdutil.GetString(md, "entrypoint.id"))
h.md.entryPointProxyProtocol = mdutil.GetInt(md, "entrypoint.ProxyProtocol")
h.md.entryPointKeepalive = true
if mdutil.IsExists(md, "entrypoint.keepalive") {
h.md.entryPointKeepalive = mdutil.GetBool(md, "entrypoint.keepalive")
}
h.md.entryPointKeepalive = mdutil.GetBool(md, "entrypoint.keepalive")
h.md.entryPointCompression = mdutil.GetBool(md, "entrypoint.compression")
h.md.entryPointReadTimeout = mdutil.GetDuration(md, "entrypoint.readTimeout")
if h.md.entryPointReadTimeout <= 0 {
+5 -1
View File
@@ -530,7 +530,11 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriter, node
return
}
return resp.Close, nil
if resp.ContentLength >= 0 {
close = resp.Close
}
return
}
func upgradeType(h http.Header) string {
+5 -1
View File
@@ -393,7 +393,11 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriter, req *
return
}
return resp.Close, nil
if resp.ContentLength >= 0 {
close = resp.Close
}
return
}
func upgradeType(h http.Header) string {