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=“centos”
ID_LIKE=“rhel fedora”
VERSION_ID=“7”
PRETTY_NAME=“CentOS Linux 7 (Core)”
ANSI_COLOR=“0;31”
CPE_NAME=“cpe:/o:centos:centos:7”

CENTOS_MANTISBT_PROJECT=“CentOS-7”
CENTOS_MANTISBT_PROJECT_VERSION=“7”
REDHAT_SUPPORT_PRODUCT=“centos”
REDHAT_SUPPORT_PRODUCT_VERSION=“7”

b. Command:

caddy
example.com {
   log stdout

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

   mime {
     .csv text/csv
   }

   proxy /  <local_ip>:3000 {
       transparent
       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 example.com in browser, proxy all requests to local instance,

when open example.com/downloads/xxxx.csv, just download it.

4. Error messages and/or full log output:

the link(example.com/downloads/x.csv) 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
https://caddyserver.com/v1/docs/placeholders

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.

https://caniuse.com/#feat=download
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition