mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Question: Does the WireMock send Content-Length response header #102
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @o7g8 on GitHub (May 16, 2018).
Hello,
I need to make a response mock with a specific value of
Content-Lengthheader:Unfortunately the Assert fails and the
Content-Lengthis not part ofresponse.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
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.@StefH commented on GitHub (May 16, 2018):
For now I ignore these restricted headers in WireMock.Net:
See also https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
Did you check the original java implementation from WireMock to see if this is possible there?
@o7g8 commented on GitHub (May 17, 2018):
I haven't checked the Java implementation, so I don't know if it's possible there.
Regarding the https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx it says:
But in my example, I attempt to set the
Content-Lengthfor the response, whileWebHeaderCollection.IsRestrictedconcerns about requests.The purpose of WireMock is to allow people to mock service responses, therefore, in my opinion, it's fair to expect that the library allows building a response with any kind of content.
The user may even want to build mocks with a wrong combination and/or content of response headers in order to test client's robustness.
Another thing which I have noticed inspecting the internals of
mockServer: despite theContent-Lengthis not part of the actual response, the header is registered in the 'response' part of the server's logs. I think it's inconsistent behavior - the logs should reflect reality.I also think that if WireMock has its own ideas about allowed and not allowed request and response headers, their content and their combinations, the server should crash in the case when the inconsistency is detected instead of silently ignoring it.
If we get back to my example: when you read the
Given-RepondWithsection you get an impression that the response does contain theContent-Lengthheader, but in reality, it doesn't. And you won't notice it unless you check for it specifically. But I think you will agree that double checking of mocks/stabs state is not a best practice in tests.@StefH commented on GitHub (May 17, 2018):
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.
@StefH commented on GitHub (May 19, 2018):
I've created a PR : you take a look and review this : https://github.com/WireMock-Net/WireMock.Net/pull/142
@StefH commented on GitHub (May 25, 2018):
Solved, see NuGet 1.0.3.18