Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite http Content-Disposition header in nginx.conf location block?

I have a reverse proxy server that takes file from fileserver than sends them to user. I want to change filename before sending. I wrote a rule like below

location ~ downloads/(.*) {          
        proxy_pass         http://HOST:PORT/remote.php/dav/files/$1;
        add_header Content-Disposition 'attachment; "filename=$args"';
   }

But when i send request i get this error;

ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
like image 565
omer faruk kalkan Avatar asked Sep 15 '25 13:09

omer faruk kalkan


1 Answers

Adding a header with add_header works well with proxy pass, but if there is an existing header value in the response it will stack the values.

If you want to replace a header value (for example replace this Content-Disposition then you will have to do this in two steps:

# 1. hide the Content-Disposition from the server response
proxy_hide_header Content-Disposition;
# 2. add a new Content-Disposition header with your changes
add_header Content-Disposition 'attachment; "filename=$args"';

See my answer on a similar question here.

like image 153
Wilt Avatar answered Sep 17 '25 06:09

Wilt