Compile Caddy only as a lib for FFI usage

I’m a new Caddy user, configured a server of mine to use it, and I find it very very convenient!

I read on Caddy’s internal docs that Caddy is both a core library AND a CLI project that’s built using the core + the modules, but I did not find (or didn’t search long enough) a guide to compile Caddy only as a library (.so file, or .dll for Windows).

The goal is to embed this library in a Rust program and use FFI (or other interfaces, I guess you might know better than me on all this) to make sure my Rust program doesn’t have to suffer the maintenance burden of reimplementing tons of HTTP-related stuff (which I do using Warp and Hyper Rust libraries).

Any guide or idea on how to achieve this? :slight_smile:

Caddy is a golang project, so I don’t think that’ll be possible; Golang generally compiles as a single static binary, not

Really, Caddy is more designed as an app platform, where you plug in your own “apps” which are written in Go and compiled in as plugins (if you need custom behaviour).

If what you really need is the certificate management facilities of Caddy, then you should look at GitHub - caddyserver/certmagic: Automatic HTTPS for any Go program: fully-managed TLS certificate issuance and renewal which is the library that underlies Caddy for that functionality.

I think you’d be the only one to want this sort of thing, so you’d probably be on your own if you go down this path.

What I actually need is a proper HTTP + TLS server that is able to serve static files, all of this is straightforward in Rust, but on the other side I need this server to be able to proxy requests directly to a FastCGI server (a PHP CGI or FPM one, to be more specific).
I implemented this part using Rust tools, but I lack some key features (mostly, streaming the CGI input and output instead of buffering them). I expect Caddy to do these kind of things in a better way, that’s why I wanted to “embed” Caddy inside the Rust app. All that’s needed is to be able to compile Caddy as a library instead of a binary.

You’d probably be better off trying to port Caddy’s fastcgi implementation up Rust I’d say.

That’s an idea I didn’t have, maybe I’ll check this out :+1:

You may be better off with something like GitHub - jmjoy/fastcgi-client-rs: Fastcgi client implemented for Rust. instead though.

This is the package I’m currently using, but it buffers request and response, and for performance & memory reasons, I’d like a way to stream them, and I don’t know how to refactor this package to do so :confused: