roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.86k stars 409 forks source link

[FEATURE REQUEST] Change static Content-type header #914

Closed Fichtme closed 2 years ago

Fichtme commented 3 years ago

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

When serving static content the application returns the file with the header Content-Type | application/zip.

My problem is that i've an .apk file. If you download the static content with the header content-type application/zip. the android browser adds .zip extension to the file.

If i could change that header to application/vnd.android.package-archive. The android browser should know that it's receiving an apk file.

Describe the solution you'd like An option to change the content-type header for static files. Maybe the static middleware could use a different content-type header depending on file type? (https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)

Describe alternatives you've considered Removing gzip from my config, only allowing static content.

Additional context I just started using Roadrunner. It could be that there's already an option within roadrunner.

Using Roadrunner with symfony 4.4 rr version 2.3.1 (build time: 2021-06-30T10:16:05+0000, go1.16.5)

server:
  command: "php bin/console.php baldinof:roadrunner:worker"
  # If you are using symfony 5.3+ and the new Runtime component:
  # remove the previous `command` line above and uncomment the line below.
  # command: "php public/index.php"
  env:
    APP_RUNTIME: Baldinof\RoadRunnerBundle\Runtime\Runtime

http:
  address: 0.0.0.0:9000
  middleware: ["static", "gzip" ]
  uploads:
    forbid: [ ".php", ".exe", ".bat" ]
  static:
    dir: "public"
    forbid: [ ".php", ".htaccess", ".json" ]
status:
  address: 0.0.0.0:9010

logs:
  mode: production
  channels:
    http:
      level: debug # Log all http requests, set to info to disable
    server:
      level: info # Everything written to worker stderr is logged
      mode: raw
    metrics:
      level: error
rustatian commented 2 years ago

Hey @Fichtme , thanks for the FR. Do I understand correctly, that your application returns the .apk file, with the application/zip content-type header and you want to change this header in the RR plugin to the proper header for the .apk file according to the mime types ?

Fichtme commented 2 years ago

Yeah, that's exactly what i want. But if that's not possible maybe a workaround to define the header for each file type?

rustatian commented 2 years ago

But, why you can't send the proper header from the application?

rustatian commented 2 years ago

I guess the problem is in the gzip middleware which is set in the list of the middleware. You may also overwrite the response header with this option: https://github.com/roadrunner-server/roadrunner/blob/master/.rr.yaml#L674