-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caddyhttp: Add support for triggering errors from try_files
#4346
Conversation
While reading through the code, I was reminded that |
The first example in the description has a typo, is it
|
No, I did that on purpose because this PR doesn't add They're subtly different. Using |
Got it. I like the implementation. This make
Am I correct in this way? |
Yeah, pretty much. It will rewrite to the first argument that matches a file that exists on disk, or immediately emit an error if it reaches an argument that looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this actually looks alright. Thanks for the contribution!
26734fd
to
338ea5e
Compare
338ea5e
to
dc35b1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I still think it's good that matchers don't return errors, especially since returning an error can be an optional utility like in this case, this approach seems better than actual error return value.
See #4344, this is a first step towards completing that issue.
Nginx supports a couple pieces of functionality in its implementation of
try_files
that allow handling the request either as an HTTP error, or by routing to a named location block. http://nginx.org/en/docs/http/ngx_http_core_module.html#try_filesFor Caddy, I think it would be quite beneficial to add support to
try_files
for triggering an error as a fallback case, to short-circuit the request handling early. In many cases, it's not simply the case of "try_files matches, or doesn't".The one potentially contentious bit here, implementation-wise, is the usage of a placeholder
http.matchers.error
as a way to carry the error from the matcher logic up to the HTTP handler chain logic. I'm hoping that this would have a minimal performance impact, but I'm not totally certain, haven't benchmarked. It's also I guess kinda cross-cutting concerns. But I don't really see a cleaner way to do this. We can't user.Context()
directly, because that's immutable at this point, so the replacer, being mutable, is the mechanism that would let us do it.Anyways, an example of how this would look:
Given the files:
/srv/foo.js
,/srv/index.php
,/srv/bar.php
Whereas without this,
curl localhost:8080/foo.php
would be sent through fastcgi when the file is already known not to exist.