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

Add simple streaming API #46

Closed
clue opened this issue Sep 4, 2015 · 3 comments
Closed

Add simple streaming API #46

clue opened this issue Sep 4, 2015 · 3 comments

Comments

@clue
Copy link
Owner

clue commented Sep 4, 2015

An experimental streaming API has been implemented via #31. However, it's quite cumbersome to work with.

In particular, one still has to wait on a promise progress event until one can access a stream object.

Instead, we should add a simple API that returns a stream right away and then emits events on it once the HTTP response comes in.

@clue
Copy link
Owner Author

clue commented Sep 4, 2015

Also take connection hijacking into account for protocols that write outgoing data even after receiving the response headers.

@clue
Copy link
Owner Author

clue commented Mar 5, 2016

This feature will likely be resolved with #30. API draft:

$browser->get($url)->then(function (Response $response) {
    $stream = $response->stream();

    $stream->on('data', function ($chunk) {
        echo $chunk;
    });
});

@clue
Copy link
Owner Author

clue commented Apr 2, 2016

I've played around with several approaches to a sane streaming API while implementing this via #56:

  • The response could implement the ReadableStreamInterface. This works out reasonably well for the receiving side through the decorator pattern, but does not really fit for outgoing requests.
  • The fetch API offers additional methods and requires a custom Response object which still has to implement the base ResponseInterface. This works out reasonably well for the receiving side through the decorator pattern, but does not really fit for outgoing requests.
  • The fetch API resolves as soon as the headers has been received without waiting for the whole body. This is the main takeaway here.

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

1 participant