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

Server response body doesn't match Content-Length, RawHTTP crashes #65

Closed
kwrooijen opened this issue Dec 12, 2022 · 2 comments
Closed

Comments

@kwrooijen
Copy link

Currently when a response returns less data than specified in Content-Length, RawHTTP will crash

if (actuallyRead < 0) {
throw new IOException("InputStream provided " + offset + ", but " + bodyLength + " were expected");

In my case I'm not the owner of the server, I can't fix this flaw. So even though the server is technically incorrect, I still want to be able to handle it.

A possible solution would be to add a flag to indicate that I want to either consume Content-Length amount or less. If it is less than Content-Length then I want to pull as much as possible without crashing.

@kwrooijen kwrooijen changed the title Server doesn't send enough data, RawHTTP crashes Server response body doesn't match Content-Length, RawHTTP crashes Dec 12, 2022
@renatoathaydes
Copy link
Owner

When the server does that, it's completely impossible to tell whether the server just gave the wrong value for the header, or if it crashed and failed to send the full response.

I can add an option to treat an incomplete body as "expected" but that feels very unreliable.

renatoathaydes added a commit that referenced this issue Aug 22, 2023
@renatoathaydes
Copy link
Owner

I added an option on RawHttpOptions to allow for this, see example in the test:
97d94ef#diff-406613a18b54c44acab140482b0332c4d4b0cf646f2465c6d4c818dd0bbd5f33R212

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

No branches or pull requests

2 participants