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

API for receiving interim responses (including early hints) #1716

Open
jasnell opened this issue Oct 2, 2023 · 2 comments
Open

API for receiving interim responses (including early hints) #1716

jasnell opened this issue Oct 2, 2023 · 2 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@jasnell
Copy link

jasnell commented Oct 2, 2023

What problem are you trying to solve?

Early hints (103 responses) are not the only kind of interim response the http spec allows for. It would be ideal for fetch to provide a means of receiving and processing interim responses.

What solutions exist today?

For fetch, none.

How would you solve it?

Define a new InterimResponse dictionary:

dictionary InterimResponse {
  unsigned short status;
  ByteString statusText;
  USVString url;
  Headers headers;
}

Define a new FetchPromise that extends Promise<Response> and implements Symbol.asyncIterator, returning an AsyncIterable of InterimResponses. The fetch() method would return this new FetchPromise, allowing, for example:

const fetchPromise = fetch('https://...');  // note no await

for await (const interimResponse of fetchPromise) {
  // process the interim response
}

const resp = await fetchPromise;

Anything else?

Original discussion for this mechanism here: https://docs.google.com/document/d/1P4MskkFd3HHFPGDr01O3wdFXukmX9i0jAb5uh9v9x8Q/edit

@jasnell jasnell added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Oct 2, 2023
@annevk
Copy link
Member

annevk commented Oct 2, 2023

#607 is the solution I had in mind for this. In combination with events.

@jasnell
Copy link
Author

jasnell commented Oct 2, 2023

Hmm... my key concern there is that #607 (and the whole observer/events model) just feels unnecessarily overweighted for this. I could certainly be convinced otherwise, tho as FetchObserver would certainly help with other use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

2 participants