Write POST or PUT request body to a file

I have wanted to use Caddy to write POST request-bodies to files probably three different times in the last year, and I always end up at this thread
where @matt says it’s easy with v2, but doesn’t answer the question because
of some odd tangent about the license.

Could you please explain how to do this, @matt, I did review the docs, but it wasn’t apparent.

I know this isn’t a common config of a http server, but this ability can be super powerful for some circumstances.

I love Caddy. I just wrote an article about how to overcome Chrome camera access failures due to HTTP (you must HTTPS for Chrome camera access) in local environs, ie 192.168.x.x using DuckDns and Caddy:
Kinda narrow for JS devs having camera issues, but it can help them figure out why the browser is acting weird using HTTP.

1 Like

Hey Cameron, welcome!

So if I understand correctly you want to serve static files with POST or PUT requests as well as GET? I imagine you don’t actually intend to have the web server write or overwrite files on disk on arbitrary HTTP requests, right? Can you clarify what you’re trying to do?

The request method can be easily changed using the rewrite handler: JSON Config Structure - Caddy Documentation

I fully intend for Caddy to overwrite files on the filesystem.

I want to take the POST request body and put it on the filesystem of the Caddy machine, it will help with debugging/testing/writing WebRTC SDPs for dev purposes. :slight_smile:

Ah… yikes. Well… for obvious reasons, Caddy doesn’t write requests to files on disk out of the box.

It’s easy to write a plugin that does this though. The plugin should probably utilize CertMagic’s storage interface so it’s not limited to just files on disk. (This is how Caddy can store stuff in databases, etc.)

1 Like

Cool, Matt, I was thinking it was an out of the box type thing from the post I linked. But I understand, something like that might just get abused and cause problems.
Thanks for the help.

That linked topic was asking about returning static files from POST requests, not creating/writing static files from POST/PUT requests.

That’s awesome! Cool to see people using the plugin I just wrote a week ago to do some cool things :smiley:

1 Like

Whoops, you are correct! Sorry about my confusion.
I really appreciate that you took time to respond, and that you built such an awesome server. (And I love the certmagic project also. :slight_smile: )


It’s awesome you wrote that! It totally makes doing SSL on the LAN on private IP’s a breeze! So awesome. Otherwise it’s so easy to go down the rabbit-hole trying to figure out how to trick the browser, or rig up some other wacky way to do SSL on the LAN to private IP’s.
I like it a lot.

1 Like

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