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

DataStreamRequest should produce the initial response before the stream #3401

Open
jshier opened this issue Jan 25, 2021 · 1 comment
Open

Comments

@jshier
Copy link
Contributor

jshier commented Jan 25, 2021

As mentioned in #3210, DataStreamRequest isn't as useful as it could be right now since it doesn't return the initial response info until after the stream is completed. If we implement urlSession(_:dataTask:didReceive:completionHandler:) we may gain more visibility into the initial responses, as well as the separate boundary responses parsed for us by URLSession.

@zacwest
Copy link

zacwest commented Jan 26, 2021

For the future person looking at this issue, the flow appears to be:

  • didReceiveResponse (overall)
  • didReceiveResponse (chunk)
  • data (n times)
  • didReceiveResponse (chunk)
  • data (n times)

(etc)

You can also find an example server-side implementation in Home Assistant:

https://github.com/home-assistant/core/blob/ac3a6aaa8cdb005b3c900f9d9671e5a859351060/homeassistant/components/camera/__init__.py#L183-L223

jshier added a commit that referenced this issue Aug 31, 2023
### Issue Link 🔗
#3401

### Goals ⚽
This PR adds `onHTTPResponse` closure hooks to `DataRequest` /
`UploadRequest` and `DataStreamRequest` to enable the cancellation of
requests before data is transferred, requests that need to check
response info for later parsing, or peculiar requests that may trigger
multiple response callbacks, like MJPEG streams.

### Implementation Details 🚧
Like the other value hooks, this API accepts a single closure. The only
unique bit here is that there's second, disfavored, version of the API
that allows the user to return `ResponseDisposition` value to cancel or
end the request without the body.

### Testing Details 🔍
Streaming tests are being updated to check these events always fire
before the other events. More tests are needed around cancellation or
ending behavior to ensure that's really possible.
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