Thanks for getting back to me so quickly.
I put these lines within the handle_path:
redir /public /public/
handle_path /public* {
root * /srv/domain/source/versions/public
@mp4 /srv/domain/source/versions/public/ *.mp4
header @mp4 Content-Disposition attachment
file_server browse
}
I received the following error message:
{"level":"info","ts":1675392237.6160033,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
Error: adapting config using caddyfile: parsing caddyfile tokens for 'handle_path': getting matcher module '/srv/domain/source/versions/public/: module not registered: http.matchers./srv/domain/source/versions/public/
I removed the named matcher (putting that problem aside for a moment) and tried this to see if a download would be forced:
redir /pubfiles /pubfiles/
handle_path /pubfiles* {
root * /srv/domain/source/versions/public
header /srv/domain/source/versions/public/ *.mp4 Content-Disposition attachment
file_server browse
}
The error went away but the browser streamed the file rather than downloaded it. I moved the header directive to outside handle_path and also ran a scenario where I made the header path the same as the domain root. In all cases, the file didn’t download. Here’s an excerpt from the access log.
http.log.access.log1 handled request {"request": {"remote_ip": "", "remote_port": "47218", "proto": "HTTP/2.0", "method": "GET", "host": "", "uri": "/pubfiles/1.mp4", "headers": {"X-Forwarded-Proto": ["https"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Mode": ["navigate"], "Cf-Ipcountry": [""], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"], "Upgrade-Insecure-Requests": ["1"], "X-Forwarded-For": [""], "Cf-Ray": ["7937f1018ef57572-LHR"], "Priority": ["u=1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0"], "Accept-Language": ["en-GB,en;q=0.5"], "Dnt": ["1"], "Sec-Fetch-Site": ["same-origin"], "Sec-Gpc": ["1"], "Accept-Encoding": ["gzip"], "Cf-Visitor": ["{\"scheme\":\"https\"}"], "Sec-Fetch-User": ["?1"], "Cookie": [], "Cf-Connecting-Ip": [""], "Cdn-Loop": ["cloudflare"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": ""}}, "user_id": "", "duration": 0.223048749, "size": 3971279, "status": 200, "resp_headers": {"X-Frame-Options": ["SAMEORIGIN"], "Content-Length": ["3971279"], "X-Permitted-Cross-Domain-Policies": ["none"], "Alt-Svc": ["h3=\":443\"; ma=2592000"], "Accept-Ranges": ["bytes"], "Server": ["Caddy"], "Content-Security-Policy": ["frame-ancestors 'self'"], "Referrer-Policy": ["no-referrer"], "Content-Type": ["video/mp4"], "Last-Modified": ["Fri, 03 Feb 2023 02:18:48 GMT"], "Permissions-Policy": ["geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()"], "X-Robots-Tag": ["none"], "Strict-Transport-Security": ["max-age=630720000;"], "X-Download-Options": ["noopen"], "Etag": ["\"rphfrc2d49b\""], "X-Content-Type-Options": ["nosniff"]}}
I guess, then, why is the file not downloading and what is the matcher module error about?
N.B. As you can, I proxy via Cloudflare but that’s never stopped me getting this working before with different servers.