diff --git a/changelog/@unreleased/pr-495.v2.yml b/changelog/@unreleased/pr-495.v2.yml new file mode 100644 index 00000000..16a71958 --- /dev/null +++ b/changelog/@unreleased/pr-495.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Add request host override option + links: + - https://github.com/palantir/conjure-go-runtime/pull/495 diff --git a/conjure-go-client/httpclient/client_params.go b/conjure-go-client/httpclient/client_params.go index f544d5c3..8bb42097 100644 --- a/conjure-go-client/httpclient/client_params.go +++ b/conjure-go-client/httpclient/client_params.go @@ -158,6 +158,14 @@ func WithUserAgent(userAgent string) ClientOrHTTPClientParam { return WithSetHeader("User-Agent", userAgent) } +// WithOverrideRequestHost overrides the request Host from the default URL.Host +func WithOverrideRequestHost(host string) ClientOrHTTPClientParam { + return WithMiddleware(MiddlewareFunc(func(req *http.Request, next http.RoundTripper) (*http.Response, error) { + req.Host = host + return next.RoundTrip(req) + })) +} + // WithMetrics enables the "client.response" metric. See MetricsMiddleware for details. // The serviceName will appear as the "service-name" tag. func WithMetrics(tagProviders ...TagsProvider) ClientOrHTTPClientParam {