[Feature Request] Ability to change request scheme when modifying a forwarded request
Describe the feature request (I am describing this feature in terms of the Java client, which I primarily use to interface with Mockserver instances)
Mockserver allows one to change the request scheme (e.g. HTTP -> HTTPS) when doing a simple HTTP forward action (e.g. HttpForward.forward()), but does not allow this when modifying a request before forwarding. I would request that this feature be added to the HttpOverrideForwardedRequest or HttpRequestModifier classes (where ever it makes more sense).
What you are trying to do Change the request scheme from HTTP to HTTPS while also overriding or modifying the request and/or response
The solution you'd like I would like to be able to change the scheme thus:
private void createHostHeaderForwardingProxy(MockServerClient client, String remoteHost, int remotePort, String path) {
client.when(HttpRequest.request().withPath(path))
.forward(
HttpOverrideForwardedRequest.forwardOverriddenRequest()
.withRequestModifier(HttpRequestModifier.requestModifier()
.withHeaders(
HeadersModifier.headersModifier().replace(
Header.header("Host", remoteHost + ":" + remotePort)
)
)
)
.withScheme(HttpForward.Scheme.HTTPS)
);
}
Describe alternatives you've considered
At the moment I'm chaining two Mockserver instances to change the scheme, then subsequently change the header. I cannot modify the Host header in the service that I am testing.
Hello. What you are describing can be done currently with:
HttpRequest.withSecure(isSecure)
Example:
.forward(
HttpOverrideForwardedRequest.forwardOverriddenRequest()
.withRequestOverride(
HttpRequest.request()
.withSecure(true)));