Set mime type on proxy header_downstream

1. My Caddy version (caddy -version):

Caddy v1.0.4 (h1:wwuGSkUHo6RZ3oMpeTt7J09WBB87X5o+IZN4dKehcQE=)

2. How I run Caddy:

a. System environment:

NAME=“CentOS Linux”
VERSION=“7 (Core)”
ID_LIKE=“rhel fedora”
PRETTY_NAME=“CentOS Linux 7 (Core)”


b. Command:

caddy {
   log stdout

   header /downloads/ {
     content-type "text/csv"

   mime {
     .csv text/csv

   proxy /  <local_ip>:3000 {
       header_downstream content-type {>content-type}

3. The problem I’m having:

i got static files in /downloads, how to config caddy to achieve this:

when open in browser, proxy all requests to local instance,

when open, just download it.

4. Error messages and/or full log output:

the link( will open in browser, not open a download dialog

5. What I already tried:

mime, or header downstream

6. Links to relevant resources:

Hi @dfang,

This isn’t a problem with Caddy, per se - I’d wager Caddy’s working exactly as you’ve configured it. Your issue is that you’re going about it the wrong way.

Using {>Content-Type} just tells your Caddy server to copy whatever the client set as their content type header in the incoming request.

{>Header} Any request header, where “Header” is the header field name

This is probably not useful at all, and it is definitely not how you go about getting a browser to download a file instead of displaying it inline. Content-Type is to signal the browser what the file is, not how to handle it.

There is a HTML5 download attribute you can use for anchor links. You could also set the Content-Disposition header. Either should work to inform the browser your intent for the file to be downloaded, not viewed.

Can I use... Support tables for HTML5, CSS3, etc
Content-Disposition - HTTP | MDN

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.