Developing a Plugin but which type?

I am trying to write a plugin to do proprietary security auth follow (send secret data to an endpoint, once verified, it redirects you back to your routes (that can be protected or not), after it gives a 200.

But I am confused what I really need. Here’s what my nginx config looks like, and I want to get away from it:

    location = @login {
        internal ;
        rewrite ^ "https://secure-login-host-verifier/login" redirect;
    location = @validate {
        internal ;
        proxy_http_version 1.1;
        proxy_pass "https://secure-login-host-verifier/validate";
        proxy_pass_request_body "on";
        proxy_set_header Host SET_CORRECT_HEADER

    location / {
        auth_prot "on"; #protect this route - can be selectively turned on and off for let's say *.png files, etc.
        proxy_connect_timeout 15s;
        proxy_http_version 1.1;
        proxy_pass http://my-app-host;

How do I get started?

I’ll write a wiki for this if I get it done – with basics on it – right . I read it mholt’s twitter that people want more examples but they are not willing to share theirs…

1 Like

I would start here:

You probably want an HTTP handler plugin, since you want to extend the functionality of Caddy handling HTTP requests. As described here your module will have a name like http.handlers.foobar.

Thanks for being willing to contribute to the wiki! Hope this helps.

Hi Matt,

Thanks for the reply! I got the basics of it working – all just had to be put in the Middleware…

Now, how do I selectively apply the “auth” to specific URI routes?

I guess I am confused on how to get that info, and selectively enable or disable per route. Any pointers would be helpful!

Thanks again.


Use request matchers:

If you registered your plugin as a “handler directive”, then you automatically get support for this in the Caddyfile.

1 Like

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