Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

[FEATURE REQUEST] Support X-Sendfile Header #9

Closed
alexander-schranz opened this issue Jun 17, 2021 · 8 comments · Fixed by #56
Closed

[FEATURE REQUEST] Support X-Sendfile Header #9

alexander-schranz opened this issue Jun 17, 2021 · 8 comments · Fixed by #56
Assignees
Labels
C-enhancement Category: enhancement. Meaning improvements of current module, transport, etc.. P-HTTP Plugin: HTTP
Milestone

Comments

@alexander-schranz
Copy link

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
Copy link
Member

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 👍🏻

@rustatian rustatian self-assigned this Jun 17, 2021
@alexander-schranz
Copy link
Author

alexander-schranz commented Jun 17, 2021

@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:

In symfony the x-sendfile header is only written when the x-sendfile-type seems to be given to the requests and no accel map is given:

@rustatian
Copy link
Member

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

@wolfy-j
Copy link

wolfy-j commented Jun 17, 2021

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:

  • proxying files
  • pre-authorized connect to WS
  • streaming and etc

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

@rustatian
Copy link
Member

Feature accepted for the v2.5.0

@rustatian rustatian transferred this issue from roadrunner-server/roadrunner Sep 18, 2021
@rustatian rustatian added A-module C-enhancement Category: enhancement. Meaning improvements of current module, transport, etc.. P-HTTP Plugin: HTTP labels Sep 18, 2021
@rustatian rustatian added this to the v2.5.0 milestone Sep 18, 2021
@rustatian
Copy link
Member

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

RoadRunner automation moved this from To do to Done Oct 6, 2021
rustatian added a commit that referenced this issue Oct 6, 2021
## Description of Changes

- Add support for the access logs at `Info` log level.
Fields:
`method` - http method.
`remote_addr` - request remote address.
`bytes_sent` - content-length,
`http_host` - host.
`request` - request Query.
`time_local` - local time in Common Log Format.
`request_length` - request body with headers size (content-len + size of all headers) in bytes. Max allowed headers size for the RR is 1MB.
`request_time` - request processing time in seconds with a milliseconds resolution.
`status` - http response status.
`http_user_agent` - http user [agent](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent)
`http_referer` - http [referer](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer)

- ✏️ Access logs turned off by default, to turn on, please, use the following field in the configuration:
```yaml
http:
  address: 127.0.0.1:58332
  max_request_size: 1024
  access_logs: true <----------------- NEW
  middleware: [ ]
  pool:
    num_workers: 2
    max_jobs: 0
    allocate_timeout: 60s
    destroy_timeout: 60s
```

- ✏️ HTTP middleware to handle Symfony's `X-Sendfile` [header](#9).
```yaml
http:
  address: 127.0.0.1:44444
  max_request_size: 1024
  middleware: ["sendfile"] <----- NEW MIDDLEWARE

  pool:
    num_workers: 2
    max_jobs: 0
    allocate_timeout: 60s
    destroy_timeout: 60s
```
@alexander-schranz
Copy link
Author

Awesome thank you all 👍

@rustatian
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-enhancement Category: enhancement. Meaning improvements of current module, transport, etc.. P-HTTP Plugin: HTTP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants