whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.11k stars 330 forks source link

Flag for "Terminate on Response Body"? #1382

Open fowl2 opened 2 years ago

fowl2 commented 2 years ago

<a ping> (Hyperlink auditing), navigator.sendBeacon(), and the keepalive flag (once the parent document has been unloaded) have a concept of terminating the request once the response body starts to be received as these are "fire and forget" requests and there is nowhere for a response to go.

eg. in Hyperlink auditing:

User agents must ignore any entity bodies returned in the responses. User agents may close the connection prematurely once they start receiving a response body.

Would it make sense to add a flag and make this explicit? I'm not proposing this be exposed to web content because it doesn't seem that useful, but I guess it might be?

related: https://github.com/whatwg/fetch/issues/679


Aside: I guess the wait is for the start of the body rather than the status to allow for any cookies, etc. to be set by the response?

fowl2 commented 2 years ago

Oh and in the interests of reducing header bloat, it also might make sense for these requests to stop implicitly adding the various Accept headers? That would be a behaviour change though.

annevk commented 2 years ago

They can terminate the fetch from the processResponse callback already. I'm not sure it's worth automating that through an additional request boolean.