Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No option to suppress content-length header on the response of forwarded request #870

Closed
annayyagari opened this issue Sep 18, 2020 · 2 comments

Comments

@annayyagari
Copy link

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:

  1. Run mock server as a java proxy from command line 5.11.1 jar
  2. Do not define any expectations, such that request gets forwarded to proxyRemoteHost
  3. Verify Response

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

@jamesdbloom
Copy link
Collaborator

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.

@jamesdbloom
Copy link
Collaborator

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");
                    }
                }
            );

@jamesdbloom jamesdbloom removed the next label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants