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

Is is possible to read the response before the whole request body is sent? #315

Closed
fatfisz opened this issue Jun 4, 2016 · 4 comments
Closed

Comments

@fatfisz
Copy link

fatfisz commented Jun 4, 2016

There's a scenario in which a big file is being sent to the server from the client, and after reaching a request body size limit the server responds with a 413 error. In this case I'd like to cancel the request on the client.

It wasn't possible to handle such scenario with XMLHttpRequest. Is the fetch API able to do it?

I guess the more accurate question is: is promise returned by fetch(...) fulfilled with a response before the request body stream is done?

Sorry if the question has an obvious answer, I couldn't make it out from reading the spec.

@jakearchibald
Copy link
Collaborator

The server doesn't provide any kind of response until it's received the entire request, which includes headers and body. Fetch resolves once response headers (but not the body) have been fully received.

Once you have a 413, the request should have finished sending.

@fatfisz
Copy link
Author

fatfisz commented Jun 4, 2016

Thanks for the quick response!

Actually, the server should be able to responsd whenever, shouldn't it? For example there's an nginx setting client_max_body_size that makes it respond with a 413 error after reaching the limit, but before the full request body was transferred. Correct me if I'm wrong, but the problem lied with the browsers, which would not allow reading the response before the whole body was sent.

If fetch resolves after the response headers are sent, then I should be able to cancel the request on the client side. That's cool!

@mnot
Copy link
Member

mnot commented Jun 6, 2016

HTTP servers aren't required to read the entire request before responding.

See discussion on #229 for fetch() details.

@annevk
Copy link
Member

annevk commented Jun 6, 2016

"I guess the more accurate question is: is promise returned by fetch(...) fulfilled with a response before the request body stream is done?" Yes, this can be the case. I think @jakearchibald was not aware of the conversation pointed out by @mnot. Closing this since there doesn't seem to be a problem here with the standard.

Why wasn't this possible with XMLHttpRequest by the way? That sounds wrong...

@annevk annevk closed this as completed Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants