Merge pull request #2834 from muzhi1991/fix/openai-compat-host-header

fix(util): forward custom Host header to upstream
This commit is contained in:
Luis Pater
2026-04-21 20:29:14 +08:00
committed by GitHub

View File

@@ -47,6 +47,14 @@ func applyCustomHeaders(r *http.Request, headers map[string]string) {
if k == "" || v == "" {
continue
}
// net/http reads Host from req.Host (not req.Header) when writing
// a real request, so we must mirror it there. Some callers pass
// synthetic requests (e.g. &http.Request{Header: ...}) and only
// consume r.Header afterwards, so keep the value in the header
// map too.
if http.CanonicalHeaderKey(k) == "Host" {
r.Host = v
}
r.Header.Set(k, v)
}
}