Closed annayyagari closed 2 years ago
I agree that makes sense.
This feature request has been accepted, new feature requests are prioritised on Trello, so closing issue in GitHub, only bugs or unaccepted feature requests will stay in GitHub, so that new feature backlog can be more effectively managed, see: https://trello.com/c/1BVqm032/179-allow-suppression-of-content-length-header-on-the-response-of-forwarded-request
However when this feature is implemented this issue will be checked so please continue any conversation related to this issue here.
I've now implemented a fix so Content-Length is always removed (see #914), however, I now release there was always a way to suppress these headers, which was included in the documented examples, as follows:
new MockServerClient("localhost", 1080)
.when(
request()
.withPath("/some/path")
)
.forward(
new ExpectationForwardCallback() {
@Override
public HttpRequest handle(HttpRequest httpRequest) throws Exception {
return request()
.withPath(httpRequest.getPath())
.withMethod("POST")
.withHeaders(
header("x-callback", "test_callback_header"),
header("Content-Length", "a_callback_request".getBytes(UTF_8).length),
header("Connection", "keep-alive")
)
.withBody("a_callback_request");
}
},
new ExpectationForwardAndResponseCallback() {
@Override
public HttpResponse handle(HttpRequest httpRequest, HttpResponse httpResponse) throws Exception {
return httpResponse
.withHeader("x-response-test", "x-response-test")
.removeHeader(CONTENT_LENGTH.toString())
.withBody("some_overridden_response_body");
}
}
);
Describe the issue No option to suppress content-length header on the response of forwarded request
What you are trying to do Response of forwarded request is always setting Content-length and Connection headers, this is causing issues on our application
MockServer version The version you are using 5.11.1 jar
To Reproduce Steps to reproduce the issue:
Expected behaviour Adding Content-length and Connection headers
There are ways to suppress these headers if mocked response is defined in the expectation but not on the forwarded request.
Please suggest if there is any work around for this. Thanks