Skip to content

Commit 8ced7a5

Browse files
authored
Merge pull request router-for-me#2834 from muzhi1991/fix/openai-compat-host-header
fix(util): forward custom Host header to upstream
2 parents 3444820 + eba561b commit 8ced7a5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

internal/util/header_helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func applyCustomHeaders(r *http.Request, headers map[string]string) {
4747
if k == "" || v == "" {
4848
continue
4949
}
50+
// net/http reads Host from req.Host (not req.Header) when writing
51+
// a real request, so we must mirror it there. Some callers pass
52+
// synthetic requests (e.g. &http.Request{Header: ...}) and only
53+
// consume r.Header afterwards, so keep the value in the header
54+
// map too.
55+
if http.CanonicalHeaderKey(k) == "Host" {
56+
r.Host = v
57+
}
5058
r.Header.Set(k, v)
5159
}
5260
}

0 commit comments

Comments
 (0)