Žiga sternad
03/11/2024, 10:09 AMuser-agent
header as it is sent from the client, proxied via. Wiremock, to the server. In my case, we need to forward the exact value as it was sent by the client.
I have tried to create an extension to remove and re-add the header, with the code below:
public class UrlAndHeadersModifyingFilter implements StubRequestFilterV2 {
@Override
public RequestFilterAction filter(Request request, ServeEvent serveEvent) {
String originalUserAgent = "example-user-agent";
Request wrappedRequest = RequestWrapper.create()
.removeHeader("User-Agent")
.addHeader("User-Agent", originalUserAgent)
.wrap(request);
return RequestFilterAction.continueWith(wrappedRequest);
}
@Override
public String getName() {
return "url-and-header-modifier";
}
}
I can see the value being updated in the http://localhost:9999/__admin/requests logs, but the server receives the updated version of the header: apache-httpClient/5.3.1 (Java/17.0.9)
I also tried to enable .notifier(new ConsoleNotifier(true))
and I see all requests/responses in the terminal. All the request logs contain the original User-agent that is coming from the client.
Am I missing something? 😐
I would like to know if this is even solvable with the Wiremock, or is it a bug or something that is not supported?
Really appreciate some thoughts / feedback on this 🙏 🙇
cc: @TomTom
03/11/2024, 11:32 AMHttpClientFactory
so that’s the nuclear option if you can’t get the Apache client to play.Žiga sternad
03/11/2024, 11:54 AMcom.github.tomakehurst.wiremock.http.client.HttpClient
List<String> FORBIDDEN_REQUEST_HEADERS = List.of(TRANSFER_ENCODING, CONTENT_LENGTH, "connection", USER_AGENT);
to
List<String> FORBIDDEN_REQUEST_HEADERS = List.of(TRANSFER_ENCODING, CONTENT_LENGTH, "connection");
… and now the proper user-agent is forwarded to the server ✅
Do you know, is there a reason why this header is forbidden to be forwarded?Tom
03/11/2024, 11:55 AMTom
03/11/2024, 11:59 AMpreserveUserAgentProxyHeader
in the same fashion as preserveHostHeader
Tom
03/11/2024, 11:59 AMŽiga sternad
03/11/2024, 12:02 PMTom
03/11/2024, 12:02 PMŽiga sternad
03/11/2024, 12:10 PMTom
03/11/2024, 12:11 PMŽiga sternad
03/11/2024, 12:17 PMproxyAll
or enableBrowserProxying
or none …?Tom
03/11/2024, 12:20 PM