add custom http response header for reverse proxy

This commit is contained in:
ginuerzh
2024-11-07 11:04:42 +08:00
parent a12870e766
commit 3db20563d2
5 changed files with 19 additions and 5 deletions
+11
View File
@@ -404,6 +404,7 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriter, node
req.Header.Set("Connection", "close")
}
var responseHeader map[string]string
var bodyRewrites []chain.HTTPBodyRewriteSettings
if httpSettings := node.Options().HTTP; httpSettings != nil {
if auther := httpSettings.Auther; auther != nil {
@@ -437,6 +438,7 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriter, node
}
}
responseHeader = httpSettings.ResponseHeader
bodyRewrites = httpSettings.RewriteBody
}
@@ -477,6 +479,15 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriter, node
defer resp.Body.Close()
xio.SetReadDeadline(cc, time.Time{})
if len(responseHeader) > 0 {
if resp.Header == nil {
resp.Header = http.Header{}
}
for k, v := range responseHeader {
resp.Header.Set(k, v)
}
}
ro.HTTP.StatusCode = resp.StatusCode
ro.HTTP.Response.Header = resp.Header
ro.HTTP.Response.ContentLength = resp.ContentLength