How to download file with caddy browse

1. The problem I’m having:

I have a simple server above with this contents now:


file_server browse

I will deploy it on and want to then when users open\/ Safari.kmmacros or some url like that it will start downloading the file with the name.

I basically want a server where whatever file I put inside the folders, when I push server to production, with the path I can just share the file to download instantly.

Can I achieve this with Caddy?

Thank you.

I don’t mind not using browse, I basically want a production server that locals my file system to put things to download as the files in the file system are. If users open the link, the file with exact same name and extension as I have it on the file system will be downloaded.

I read the docs on file serving and it’s not clear how I would do this.

Currently if I try to open the file I see this

I see content of it, I want for it to instantly start downloading with the file + extension as I had it in the file system myself.

I notice it adds .xml to it even though the extension is .kmmacros.

Also the file name it suggests is localhost_km_open_ Safari.kmmacros.xml if I have chrome try save the https://localhost/km/open:%20Safari.kmmacros url

Again I don’t want users to do it themselves, I want to just link to URL and open/ Safari.kmmacros gets saved instantly to their ~/Downloads folder

Really hope caddy can do this and I don’t have to write a custom go server for this.

I think you can do it by setting these headers:

@kmmacros path *.kmmacros
header @kmmacros {
	Content-Type application/octet-stream
	Content-Disposition `attachment; filename="{file}"`

This will make requests to a path that end in .kmmacros have those headers added.


That worked, thanks.

Specifically, I think you just need Content-Disposition. But yeah, that’d do it :smiley:

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