Nyholm / psr7

A super lightweight PSR-7 implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for "Early Hints" / HTTP Code 103

joergmoenke opened this issue · comments

I tried, but i could not get it to work with this library: Is it possible to do things like sending 2 responses as server response?

// init - RoadRunner is just an example
$worker     = \Spiral\RoadRunner\Worker::create();
$psrFactory = new Psr17Factory();
$psr7   = new \Spiral\RoadRunner\Http\PSR7Worker(worker        : $worker,
                                                 requestFactory: $psrFactory,
                                                 streamFactory : $psrFactory,
                                                 uploadsFactory: $psrFactory);
// ... other code here. now the interesting part:
$psr7->respond(status     : 103,
               headers    : ['Link'  => ['</static/css/bootstrap.min.css>; rel=preload; as=style',
                                         '</static/js/bootstrap.bundle.min.js>; rel=preload; as=script']],
               endOfStream: false);
$psr7->respond(status     : 200,
               body       : 'My fancy HTML that took maybe 1 second to create',
               endOfStream: true);
// exceptions following and so on

endOfStream would describe that the response stream shall be closed or not (which has not been implemented yet?).

The PSR-7 implementation in this repository does not actually handle any of the sending. We never access the response stream. That is probably handled by the PSR7Worker instance from RoadRunner.

Have you opened an issue there? If you have the Exceptions, those might point out where the stream is actually getting closed?