fix http proxy response

This commit is contained in:
ginuerzh 2024-06-25 22:09:00 +08:00
parent b99292bed8
commit 74dc03bd66
2 changed files with 16 additions and 4 deletions

View File

@ -161,14 +161,19 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
log.Debugf("%s >> %s", conn.RemoteAddr(), addr) log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
resp := &http.Response{ resp := &http.Response{
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
Header: h.md.header, Header: h.md.header,
ContentLength: -1,
} }
if resp.Header == nil { if resp.Header == nil {
resp.Header = http.Header{} resp.Header = http.Header{}
} }
if resp.Header.Get("Proxy-Agent") == "" {
resp.Header.Set("Proxy-Agent", h.md.proxyAgent)
}
clientID, ok := h.authenticate(ctx, conn, req, resp, log) clientID, ok := h.authenticate(ctx, conn, req, resp, log)
if !ok { if !ok {
return nil return nil

View File

@ -10,7 +10,8 @@ import (
) )
const ( const (
defaultRealm = "gost" defaultRealm = "gost"
defaultProxyAgent = "gost/3.0"
) )
type metadata struct { type metadata struct {
@ -20,6 +21,7 @@ type metadata struct {
hash string hash string
authBasicRealm string authBasicRealm string
observePeriod time.Duration observePeriod time.Duration
proxyAgent string
} }
func (h *httpHandler) parseMetadata(md mdata.Metadata) error { func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
@ -46,6 +48,11 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod") h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
h.md.proxyAgent = mdutil.GetString(md, "http.proxyAgent", "proxyAgent")
if h.md.proxyAgent == "" {
h.md.proxyAgent = defaultProxyAgent
}
return nil return nil
} }