From 2f2a50034ad8288fbef945dbdb1fd8b522629eff Mon Sep 17 00:00:00 2001 From: Arthur Befumo <34725560+Arthur-Befumo@users.noreply.github.com> Date: Thu, 15 Jun 2023 11:25:21 -0700 Subject: [PATCH] Add request host override option (#495) Add request host override option --- changelog/@unreleased/pr-495.v2.yml | 5 +++++ conjure-go-client/httpclient/client_params.go | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 changelog/@unreleased/pr-495.v2.yml 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 {