caddy icon indicating copy to clipboard operation
caddy copied to clipboard

caddyhttp: Implement `skip_log` handler

Open francislavoie opened this issue 3 years ago • 0 comments

Closes #4689

Introduces a new skip_log HTTP handler, which takes a matcher. If the request matches, it will be marked to skip log emission.

This is implemented by writing to a boolean flag set in the Vars map when the handler matches, then checking the value at the end of the request just before attempting to emit the log.

Caddyfile syntax:

skip_log <matcher>

Note that the matcher is not optional, in this case it is required.

At the code level, this directive is registered as a non-handler directive, because RegisterHandlerDirective will eat the matcher tokens to put it on the route.

The skip_log directive can be used multiple times, and the first matching one will set the skip log flag. No matcher short circuiting happens in this case when using the Caddyfile, because I didn't implement logic for merging multiple skip_log handlers. Technically that could be done, but it's probably not worth the effort, it would only be a super mild performance benefit for probably a lot more code.

I set the handler order for skip_log to be right near the top, alongside the other vars-ish handlers. Having it early is probably ideal because I think it makes most sense to run the matchers on an unmodified request (before any rewrite etc).

When configuring with JSON, multiple matcher sets can be configured on the one handler, which gives a very slight performance advantage if OR conditions are needed for matching.

francislavoie avatar Apr 09 '22 04:04 francislavoie

Thank you for working on this, Francis!

mholt avatar Sep 15 '22 16:09 mholt