Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Add support for Responses that produce a HTTP/1.1 chunked stream #261

Open
stuartherbert opened this issue Jul 23, 2017 · 2 comments
Open

Comments

@stuartherbert
Copy link

HTTP/1.1 provides 'Transfer-encoding: chunked' for sending a stream of data from the server.

Zend Diactoros currently doesn't seem to provide out-of-the-box support for this.

  • There's no existing Response that sets the required headers for you.
  • There's no existing implementation of StreamInterface that supports dynamic content and is compatible with the requirements of SapiStreamEmitter.

Possible solution for out-of-the-box support could be:

  • Add a DynamicStreamInterface interface that extends StreamInterface, for type-hinting in a moment
  • Add a GeneratorStream class that implements DynamicStreamInterface, and its read() method gets the required data from a PHP generator
  • Add another class that implements DynamicStreamInterface, and its read() method gets the required data from a PHP callback
  • Add a StreamResponse class that requires a DynamicStreamInterface in the constructor, sets the necessary headers for chunked stream delivery

It leaves questions around handling $maxBufferLength, and where the code goes to write the actual chunked blocks (trait? helper class?).

I have to build a solution for this, and I'm happy to contribute it back to Diactoros, if we can agree a design :)

@weierophinney
Copy link
Member

Honestly, this looks like a combination of:

  • A stream type
  • A custom emitter type

As such, it may make sense as a bridge package between Diactoros and zend-httphandlerrunner that provides the stream and the associated emitter. We would definitely promote it, and potentially offer to bring it into the zendframework organization if you wished.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-diactoros; a new issue has been opened at laminas/laminas-diactoros#13.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants