reverseproxy: Improve error message when using scheme+placeholder #3393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See the discussion here: https://caddy.community/t/proxy-upstream-placeholders/8085
So as it turns out, if you try to use a placeholder as a proxy address, it works fine, unless you also specify a scheme (i.e. the address containing
://
), which uses a different code path.For example with this Caddyfile:
The error message when adapting looks like this:
This doesn't really explain why it doesn't work. This PR adds a condition ahead of the call to
url.Parse
(which triggers that error) which gives a more useful message:Essentially this just means "omit
http://
and it'll work, or omithttps://
and usetransport { tls }
if you need HTTPS".Also as a note, currently it's impossible to use a SRV address from the Caddyfile and also use placeholders. We could add a
srv
subdirective that basically skips the parsing checks. Currently, we must parse the scheme to allow SRV because it's set as a different field in the JSON than non-SRV addresses (i.e.dial
for non-SRV, andlookup_srv
for SRV addresses). With a separate subdirective we could skip the parse step to allow placeholders to pass though... but the use-case for that is so thin that I don't think it's worth the bother for now unless someone specifically shows a valid use-case for it.