Question: UsingHead always returns 0 for Content-Length header even when explicitly specified #92

Closed
opened 2025-12-29 14:22:16 +01:00 by adam · 5 comments
Owner

Originally created by @pm7y on GitHub (Apr 16, 2018).

Originally assigned to: @StefH on GitHub.

The response to a HEAD request should be the length of the file (without the actual body) so something like this (below) should return 1024 in the Content-Length response header but it always returns 0. Something internally must be overwriting my value of "1024" back to "0".

server
    .Given(Request.Create().WithPath($"/SomeFile.zip").UsingHead())
    .RespondWith(Response.Create()
        .WithHeader("Content-Length", "1024")
    );
Originally created by @pm7y on GitHub (Apr 16, 2018). Originally assigned to: @StefH on GitHub. The response to a HEAD request should be the length of the file (without the actual body) so something like this (below) should return 1024 in the Content-Length response header but it always returns 0. Something internally must be overwriting my value of "1024" back to "0". ``` c# server .Given(Request.Create().WithPath($"/SomeFile.zip").UsingHead()) .RespondWith(Response.Create() .WithHeader("Content-Length", "1024") ); ```
adam closed this issue 2025-12-29 14:22:16 +01:00
Author
Owner

@StefH commented on GitHub (Apr 16, 2018):

This is a restricted header:

https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx

@StefH commented on GitHub (Apr 16, 2018): This is a restricted header: https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
Author
Owner

@StefH commented on GitHub (Apr 19, 2018):

@pmcilreavy Does this answer your question?

@StefH commented on GitHub (Apr 19, 2018): @pmcilreavy Does this answer your question?
Author
Owner

@StefH commented on GitHub (Apr 24, 2018):

Closing

@StefH commented on GitHub (Apr 24, 2018): Closing
Author
Owner

@o7g8 commented on GitHub (May 16, 2018):

@StefH the documentation https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx says

Tests whether the specified HTTP header can be set for the request.

But in this example the code attempts to set in the response.
Why shouldn't it be possible for a mock to specify an arbitrary value of Content-Length?

@o7g8 commented on GitHub (May 16, 2018): @StefH the documentation https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx says ``` Tests whether the specified HTTP header can be set for the request. ``` But in this example the code attempts to set in the _response_. Why shouldn't it be possible for a _mock_ to specify an arbitrary value of `Content-Length`?
Author
Owner

@StefH commented on GitHub (May 25, 2018):

Solved, see NuGet 1.0.3.18

@StefH commented on GitHub (May 25, 2018): Solved, see NuGet 1.0.3.18
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#92