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

Response Header Content-Length not available when call HEAD Method #720

Closed
bangush opened this issue Feb 7, 2022 · 9 comments
Closed

Response Header Content-Length not available when call HEAD Method #720

bangush opened this issue Feb 7, 2022 · 9 comments
Assignees
Labels

Comments

@bangush
Copy link

bangush commented Feb 7, 2022

Refer to the Previous Bug #136 and Bug #137. When call HEAD Method the Cotent-Length is not available.

const string responseBody = @"<?xml version=""1.0""?><empty/>";

wireMockServer
.Given
(Request
.Create()
.WithPath("/api")
.UsingPost()
)
.RespondWith(Response
.Create()
.WithStatusCode(HttpStatusCode.OK)
.WithHeader("content-type", "text/xml")
.WithHeader("content-length", responseBody.Length.ToString()) // this line not show during test.
.WithBody(responseBody)
);
@bangush bangush added the bug label Feb 7, 2022
@StefH StefH self-assigned this Feb 7, 2022
@bangush
Copy link
Author

bangush commented Feb 7, 2022

Hint: I randomly check multiple versions, and up-to WireMock.Net Ver 1.0.4.19 work with header contents and return the values as expected. but after that the process is broken.

{
var headers = new Dictionary<string, string>
        {
            { "Accept", "text/html" }, // OK
            { "Connection", "keep-alive" }, // OK
            { "Content-Length", responseBody.Length.ToString() }, // OK
            { "Content-Type", "text/html; charset=utf-8" }, // OK
            { "Date", "Fri, 06 Mar 2019 17:36:11 GMT" }, // OK
            { "Expect", "100-continue" }, // OK
            { "Host", "developer.mozilla.org" }, // OK
            { "If-Modified-Since", "Wed, 21 Oct 2015 07:28:00 GMT" }, // OK
            { "Keep-Alive", "timeout=5, max=1000" }, // OK
            { "Range", "bytes=0-499, -500" }, // OK
            { "Referer", "developer.mozilla.org/en-US/docs/Web/JavaScript" }, // OK 
        **//  { "Transfer-Encoding", "compress" },  // 500 Internal Server Error** 
          { "User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" }, // OK
            { "Proxy-Connection", "keep-alive" }, // OK
            { "WWW-Authenticate", "Basic YWxhZGRpbjpvcGVuc2VzYW1l" } // OK 
        };
...
...
 .WithHeaders(headers)
...
...
}

@StefH StefH added question and removed bug labels Feb 7, 2022
@StefH
Copy link
Collaborator

StefH commented Feb 7, 2022

@bangush
According to the specs, Head does not have a body.
So also not a content-length.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD

image

@StefH StefH closed this as completed Feb 7, 2022
@textbook
Copy link

As is visible in the quote:

For example, if a URL might produce a large download, a HEAD request could read its Content-Length header to check the filesize without actually downloading the file.

Per RFC9110, although:

...the server MUST NOT send content in the response. ... The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request method had been GET.

So although a HEAD response is not required to have a Content-Length, it certainly (and despite the lack of actual content) can if that length is known.

@maoso
Copy link

maoso commented Jun 6, 2023

Hi @StefH,

Is this issue going to be fixed? A head response returns the content-length of the file but WireMock not.

@dianast31
Copy link

Hi @StefH,

Is this issue going to be fixed? I have the same problem as @maoso. Is there a workaround for this bug?

@StefH
Copy link
Collaborator

StefH commented Aug 13, 2024

I will have a look if it's possible to support content-lenght for head.

@StefH StefH reopened this Aug 13, 2024
@StefH StefH added feature and removed question labels Aug 16, 2024
@StefH
Copy link
Collaborator

StefH commented Aug 16, 2024

#1158

@StefH StefH closed this as completed Aug 16, 2024
@dianast31
Copy link

#1158

Hi @StefH,

Thank you so much; we really need this feature ASAP. Could you please provide an ETA for the next release that will include this fix?

@StefH
Copy link
Collaborator

StefH commented Aug 16, 2024

Today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants