When using “handle_errors”, i have difficulties also using basicauth. I belive the problem is that http 401 unauthorized is catched by the handle_errors, and never triggering the basicauth directive. Any suggestions to how i should be able to use both basicauth while also handle 502 errors ?
4. Error messages and/or full log output:
Login dialog never shown.
5. What I already tried:
I have tried to move the basicauth around, but that makes no difference
Yes, the handle_errors looks better with the handle, it is of course only the 502 i need to handle but the reverse_proxy, but it do not change that the basichauth is not working. I simply just get and blank page. If i remove the handle_errors, basicauth is working correctly
Running this, I make a request to http://localhost:8883 in my browser. I get the basicauth prompt. If I give a bad user/pass (say bar/bar) the basicauth prompt clears and reloads (Caddy responds with a 401). If I then use the correct credentials foo/foo, then I get a HTTP 200 response with Hello World displayed.
So something funky must be going on. Can you try the above and confirm that it works for you?
Oh wow, that’s fascinating. I see what’s going on now. Adapting the configs to JSON with caddy adapt --pretty makes it obvious. Thanks for noticing that.
So when you have a host matcher, the error routes also inherit the host matcher, on a subroute that wraps the other routes. This subroute has terminal marked on it which means that once matched, no handlers are executed past that point. The implicit error handler from the above PR isn’t actually run because it’s appended after the subroute, which is “too late”.
I’ll look to make a patch to fix this, I think we can append the implicit error handler at the end of top-level subroutes maybe.