roadrunner-server / roadrunner-plugins

📦 Home for the roadrunner plugins
MIT License
25 stars 9 forks source link

[FEATURE REQUEST] Support X-Sendfile Header #9

Closed alexander-schranz closed 2 years ago

alexander-schranz commented 3 years ago

Is your feature request related to a problem? Please describe.

When having private files behind a PHP firewall you return them in Symfony as a BinaryFileResponse. When supported by the Webserver in this case the x-sendfile header will be used which just tell the webserver where the file can be found which need to be streamed out.

Describe the solution you'd like

It would be great when roadrunner would also support the x-sendfile header. I could not yet find a reference or a config how this kind of response are handled in roadrunner.

Describe alternatives you've considered

Alternative is not supporting x-sendfile Symfony does then fallback to a normal file stream to php://output.

Additional context

Apache does support x-sendfile of the sendfile mod. Nginx I think does support it out of the box. The state of caddy webserver I don't know.

rustatian commented 3 years ago

Hey @alexander-schranz. Thanks for the proposal. Could you please provide a little bit more details about how this feature works in Nginx, Apache, or Symfony? Might be some documentation. Thanks 👍🏻

alexander-schranz commented 3 years ago

@rustatian The response from PHP looks like the following in HTTP:

HTTP/1.1 200 OK
x-sendfile: /var/data/website/private-directory/file.mp4
Content-Length: 12345

The content of this response is empty and does not contain any data the Content-Length can still return the original length of the given file.

The webservers looks for the x-sendfile header if it exist it will stream the given file as response content to the user and remove the x-sendfile header from the response. The advantage is php does not need to stream it to the webserver and then webserver to the client just the webserver does stream the file directly from the

There is also some docs here:

rustatian commented 3 years ago

Great, thanks @alexander-schranz. I hope I'll implement it after the transition of the jobs and grpc will be done.

wolfy-j commented 3 years ago

Valery, this work is pretty much connected with the custom response handlers we spoke about (streaming), since we will use a similar approach with the header. So it will require some HTTP layer refactoring first. But it will open a TON of interesting possibilities:

Also, it is connected to one of the distribution methods of https://github.com/spiral/distribution

rustatian commented 3 years ago

Feature accepted for the v2.5.0

rustatian commented 2 years ago

@alexander-schranz Feature will be available for testing by the end of the week in the v2.5.0-beta.2.

alexander-schranz commented 2 years ago

Awesome thank you all 👍

rustatian commented 2 years ago

@alexander-schranz Please, test the v2.5.0-beta.2: https://github.com/spiral/roadrunner-binary/releases/tag/v2.5.0-beta.2