Fix platform-http-proxy example: reverse proxy instead of self-referential CamelHttpUrl - #207
Open
Croway wants to merge 2 commits into
Open
Fix platform-http-proxy example: reverse proxy instead of self-referential CamelHttpUrl#207Croway wants to merge 2 commits into
Croway wants to merge 2 commits into
Conversation
…ial CamelHttpUrl
The example was broken in three ways:
- The README's curl --proxy command never reached the route: servlet
containers normalize an absolute-form request line down to just the
path, discarding the target host, so the request never matched
platform-http:proxy/*.
- toD("${headers.CamelHttpUrl}") used the incoming request's own URL
(CamelHttpUrl is set from request.getRequestURL(), i.e. this
application's own address), causing the route to call itself in an
infinite loop until the HTTP connection pool exhausted (503s).
- The consumer path literal "proxy" collides with a reserved marker in
camel-platform-http that turns the endpoint into a catch-all consumer
for a Host-header-based forward proxy - a mode only implemented by
the Vert.x platform-http engine, not by camel-platform-http-starter
(the servlet/Spring MVC engine this example uses). Left as-is it
silently degrades into an unguarded catch-all matching unrelated
paths instead of 404ing.
Redesigned as a real path-based reverse proxy: requests under
/reverse-proxy/** are forwarded to a configurable backend
(reverse-proxy.target-base-uri) using camel-http's bridgeEndpoint mode,
which appends CamelHttpPath/CamelHttpQuery onto the fixed target
automatically instead of trusting a self-referential header.
Verified end-to-end against httpbin.org: query strings, root path, and
trailing-slash requests all forward correctly, and unrelated paths now
404 instead of being swallowed by the route.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgb2b9DSh1ncG7C82rwzsE
Use setHeader with a Simple/OGNL expression (${header.CamelHttpPath.substring(n)},
which invokes the real java.lang.String.substring(int) per Camel's OGNL support)
instead of a Java lambda Processor, keeping the route declarative.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgb2b9DSh1ncG7C82rwzsE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
platform-http-proxyexample was broken in three ways:curl --proxycommand never reached the route: servlet containers normalize an absolute-form request line down to just the path, discarding the target host, so the request never matchedplatform-http:proxy/*.toD("${headers.CamelHttpUrl}")used the incoming request's own URL (CamelHttpUrlis set fromrequest.getRequestURL(), i.e. this application's own address), causing the route to call itself in an infinite loop until the HTTP connection pool exhausted (503s).proxycollides with a reserved marker incamel-platform-httpthat turns the endpoint into a catch-all consumer for aHost-header-based forward proxy - a mode only implemented by the Vert.x platform-http engine, not bycamel-platform-http-starter(the servlet/Spring MVC engine this example uses). Left as-is it silently degrades into an unguarded catch-all matching unrelated paths instead of 404ing.Redesigned as a real path-based reverse proxy: requests under
/reverse-proxy/**are forwarded to a configurable backend (reverse-proxy.target-base-uri) usingcamel-http'sbridgeEndpointmode, which appendsCamelHttpPath/CamelHttpQueryonto the fixed target automatically instead of trusting a self-referential header.Test plan
mvn compileon the modulehttpbin.org:GET /reverse-proxy/get?arg1=val1forwards tohttpbin.org/get, query string preservedGET /reverse-proxyand/reverse-proxy/forward correctly to the backend root/nope,/xyz,/reverse-proxyfoo,/other/path) correctly return 404 instead of being swallowed by the route (this used to silently catch-all under the oldproxyliteral path)