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

Proxy of empty POST requests missing to content-lenght header #1872

Closed
vonatzigenc opened this issue May 12, 2022 · 0 comments · Fixed by #1873
Closed

Proxy of empty POST requests missing to content-lenght header #1872

vonatzigenc opened this issue May 12, 2022 · 0 comments · Fixed by #1873

Comments

@vonatzigenc
Copy link
Contributor

  • WireMock version: 2.33.2
  • Main-Method of WireMockServerRunner without any options

If a POST request with an empty payload is sent via a proxy mapping, the “content-length” header is lost. This causes the server to respond with status 411 (“The request must be chunked or have a content length”).

Example:

Stub Mapping:

{
  "request": {
    "urlPathPattern": "/example/.*",
    "method": "ANY"
  },
  "response": {
    "proxyBaseUrl": "https://api.app.mobiliar-sit.ch"
  }
}

Request: curl -X POST --location "http://localhost:8080/example/empty-post" -H "Content-Length: 0"

Analysis

There have been several changes which, in my opinion, lead to the behavior.

Proposed solution

  • Don't set a default ContentType at
    new ByteArrayEntity(originalRequest.getBody(), ContentType.DEFAULT_BINARY));
    • Use the content-type from header of the original request or set it to null
  • Create and add "HttpEntity", if it's an empty byte[] but content-length is set
    • Alternative: Always create HttpEntity. Drawback of this solution is, that the content-length Header will be set for all requests. (including GET).
vonatzigenc added a commit to vonatzigenc/wiremock that referenced this issue May 12, 2022
To enable valid POST requests without a body, an empty entity is required.
Otherwise, the proxy request will not include the header content-length.
Additionally, the content-type will only be set if it is already present
in the originalRequest.
This prevents a new, additional header from being set.

Signed-off-by: Christian von Atzigen <christian.vonatzigen@mobi.ch>
tomakehurst pushed a commit that referenced this issue Sep 14, 2022
To enable valid POST requests without a body, an empty entity is required.
Otherwise, the proxy request will not include the header content-length.
Additionally, the content-type will only be set if it is already present
in the originalRequest.
This prevents a new, additional header from being set.

Signed-off-by: Christian von Atzigen <christian.vonatzigen@mobi.ch>

Signed-off-by: Christian von Atzigen <christian.vonatzigen@mobi.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant