Question: Does the WireMock send Content-Length response header
See original GitHub issueHello,
I need to make a response mock with a specific value of Content-Length header:
[TestMethod]
public async Task CheckMockHeaders() {
var responseBody = @"<?xml version=""1.0""?><empty/>";
mockServer
.Given(Request
.Create()
.WithPath("/test")
.UsingPost())
.RespondWith(Response
.Create()
.WithStatusCode(200)
.WithHeader("content-type", "text/xml")
.WithHeader("Content-Length", responseBody.Length.ToString())
.WithBody(responseBody));
using (var httpClient = new HttpClient()) {
var uri = mockServer.Urls.Single() + "test";
using (var response = await httpClient.PostAsync(uri, new StringContent(""))) {
response.EnsureSuccessStatusCode();
Assert.IsTrue(response.Content.Headers.Any(x => x.Key == "Content-Length"));
}
}
}
Unfortunately the Assert fails and the Content-Length is not part of response.Content.Headers.
I suspect problem might be in the fact that the server by default assigns header Transfer-Encoding: chunked.
According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
Data is sent in a series of chunks. The Content-Length header is omitted in this case and at the beginning of each chunk you need to add the length of the current chunk in hexadecimal format…
I was not able to assign my own Transfer-Encoding: identity. I will create a separate question about it.
WireMock.Net version 1.0.3.16.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Setting Content-Length HTTP header in response using ...
I was able to get it to respect the header when I added the route by posting a request to the server. @Test...
Read more >Mock API Response Templating
Response headers and bodies, as well as proxy URLs, can optionally be rendered using Handlebars templates. This enables attributes of the request to...
Read more >11. Spring Cloud Contract WireMock
This contract specifies that any valid POST with an "id" field receives the response defined in this test. You can chain together calls...
Read more >What is the Content-Length header?
A Content-Length header is a number that indicates the size of the data in the body of the request or response in bytes....
Read more >WireMock.Net changelog - Awesome .NET - LibHunt
Net is a flexible product for stubbing and mocking web HTTP responses using ... #136 - Question: Does the WireMock send Content-Length response...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You are correct. I think that I switched Request en Response headers in my implementation.
I had some troubles some time ago when setting the
Content-Lengthheader on theIOwinResponseorHttpResponseobject.I will check that code again, and keep you informed.
Solved, see NuGet 1.0.3.18