How fast is the rewrite code?

I’m considering porting a legacy system to caddy. What makes this different is that the router stuff is not inside the framework but using the server alias and rewriting rules.

What happens when i put a thousand fast (non regexpr) rewrite and a handful of dynamic (with regexpr) rules (all having different basepaths) into the server config file? Is this a O(n) operation or are you doing something better like binary or radix search?

And by the way, what are the precedence rules among rules? This is a serious part missing in the documentation.
Does the longest prefix wins? Are simple rewrites (please call them aliases as any other server does) picked up before the regexpr?

Hey Lothar, welcome!

I haven’t benchmarked or profiled the rewrite middleware. It’ll probably undergo some significant changes either before or just after 1.0 as we optimize things and I have plans to make a standard method of request matching for directives, that will allow matching more easily than just based on path.

The rewrite directive chooses the rule with a base request path of longest length. We can probably mention this in the docs, although I was hoping this was part of “it just works” that people would expect.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.