Skip to content

Instantly share code, notes, and snippets.

@LXGaming
Last active January 22, 2025 23:14
Show Gist options
  • Save LXGaming/e7f766bdf0e88966f5c98e20728210f8 to your computer and use it in GitHub Desktop.
Save LXGaming/e7f766bdf0e88966f5c98e20728210f8 to your computer and use it in GitHub Desktop.
Caddy - Negate Request Matcher
(negate) {
# Set the initial values
vars {args[0]} false
vars {args[1]} true
# On match invert the values
vars @{args[0]} {args[0]} true
vars @{args[0]} {args[1]} false
# Create the inverse matcher
@{args[1]} `{vars.{args[1]}} != false`
}
example.com {
@allowed remote_ip 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.1/8
import negate allowed denied
# Example
handle @allowed {
respond "Allowed: {vars.allowed} / {vars.denied}"
}
# Example
handle @denied {
respond "Denied: {vars.allowed} / {vars.denied}"
}
# Example
respond @denied 403
skip_log @allowed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment