-
Notifications
You must be signed in to change notification settings - Fork 364
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
http_client_conformance_tests
Content-Length
tests are not passable with fetch as per spec
#1121
Comments
What exact tests would you want to be optional? Maybe you could create a PR to make them optional? |
I'm not sure how to read the spec...do you not get a content-length header? Or does the browser correct it for you? |
Content length denotes size of the encoded response body, it's needed, so software know how much bytes they should expect, e.g. allocate the buffer. Browsers on the other hand handles decoding of body opaquely, and you can no longer expect content length header to be exact precise. Let's say you have 200 bytes gzipped body, header would be 200, but decoded size is 250bytes, 250 would be the size of body available to browser, and we couldn't peek at the original gzipped form. |
So the browser modifies "content-length" to match the actual number of decoded bytes in the body? |
No, it modifies body, but content-length remain the same. So it's no longer body.size == content-lenght. |
But then shouldn't it be possible to make the test fail? Because Like: if (responseHeaders['content-length'] case final contentLengthHeader?) {
if (!_digitRegex.hasMatch(contentLengthHeader) || int.tryParse(contentLengthHeader) != bodySize)
throw ClientException(
'Invalid content-length header [$contentLengthHeader].',
request.url,
);
}
|
That wont work, because this check will fail for almost any normal response. By the way, that was my first attempt to just fix 1 failing test, and then it got all red 😅 |
Got it! Do you have access to the content-encoding header? Maybe we could limit the scope of the check to cases where content-encoding is not set? |
I can try to check that, but my assumption is that browser could try to guess the encoding if header is not present, but that needs confirmation. |
Browsers have Also incorporated sophisticated check when we have access to required headers:
|
Yeah! |
I'd like to make few of the test (e.g.
server headers content length bigger than actual body
) optional, because withfetch
:Ref: https://fetch.spec.whatwg.org/#ref-for-handle-content-codings%E2%91%A0
Ref: whatwg/fetch#67
The text was updated successfully, but these errors were encountered: