[
https://issues.apache.org/jira/browse/CAMEL-24625?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Federico Mariani updated CAMEL-24625:
-------------------------------------
Description:
*Use case:* building a path-based reverse proxy on platform-http — expose a
backend under a prefix (e.g. {{/reverse-proxy/**}}) and forward to it
({{http://backend/**}}), stripping the prefix. This is the standard
reverse-proxy shape (nginx {{location}}, Spring Cloud Gateway {{StripPrefix}},
Traefik {{StripPrefix}}, Envoy {{prefix_rewrite}}) and today requires manual
header surgery:
{code:java}
from("platform-http:/reverse-proxy?matchOnUriPrefix=true")
.setHeader(Exchange.HTTP_PATH,
simple("${header.CamelHttpPath.substring(14)}")) // 14 == prefix length,
duplicated by hand
.to("http://backend?bridgeEndpoint=true")
{code}
camel-servlet, camel-jetty, camel-netty-http and camel-undertow do not need
this — their consumers already make CamelHttpPath relative to the registered
consumer path, so bridgeEndpoint=true alone does the right thing. platform-http
(both the Vert.x and Spring Boot/camel-platform-http-starter engines) is the
one HTTP consumer that always reports the full raw path.
*Proposal:* add a {{stripUriPrefix}} consumer option (default {{false}}) to
PlatformHttpEndpoint. When set, the matched consumer path is removed from
CamelHttpPath (segment-boundary aware), so the reverse proxy above becomes:
{code:java}
from("platform-http:/reverse-proxy?matchOnUriPrefix=true&stripUriPrefix=true")
.to("http://backend?bridgeEndpoint=true")
{code}
CamelHttpUri/CamelHttpUrl keep the full path. Default is {{false}} to avoid a
breaking change (existing Vert.x routes rely on the full path); aligning the
default with the other consumers is left to a future major version.
*PR (core, Vert.x engine):* https://github.com/apache/camel/pull/26114
A follow-up in apache/camel-spring-boot wires the same option into the Spring
Boot platform-http engine (camel-platform-http-starter).
was:
*Use case:* building a path-based reverse proxy on platform-http — expose a
backend under a prefix (e.g. {{/reverse-proxy/**}}) and forward to it
({{http://backend/**}}), stripping the prefix. This is the standard
reverse-proxy shape (nginx {{location}}, Spring Cloud Gateway {{StripPrefix}},
Traefik {{StripPrefix}}, Envoy {{prefix_rewrite}}) and today requires manual
header surgery:
{code:java}
from("platform-http:/reverse-proxy?matchOnUriPrefix=true")
.setHeader(Exchange.HTTP_PATH,
simple("${header.CamelHttpPath.substring(14)}")) // 14 == prefix length,
duplicated by hand
.to("http://backend?bridgeEndpoint=true")
{code}
camel-servlet, camel-jetty, camel-netty-http and camel-undertow don't need this
— their consumers already make CamelHttpPath relative to the registered
consumer path, so bridgeEndpoint=true alone does the right thing. platform-http
(both the Vert.x and Spring Boot/camel-platform-http-starter engines) is the
one HTTP consumer that always reports the full raw path.
*Proposal:* add a {{stripUriPrefix}} consumer option (default {{false}}) to
PlatformHttpEndpoint. When set, the matched consumer path is removed from
CamelHttpPath (segment-boundary aware), so the reverse proxy above becomes:
{code:java}
from("platform-http:/reverse-proxy?matchOnUriPrefix=true&stripUriPrefix=true")
.to("http://backend?bridgeEndpoint=true")
{code}
CamelHttpUri/CamelHttpUrl keep the full path. Default is {{false}} to avoid a
breaking change (existing Vert.x routes rely on the full path); aligning the
default with the other consumers is left to a future major version.
Draft PR with a reference implementation: (to be linked).
> camel-platform-http: CamelHttpPath should optionally be relative to the
> consumer path (stripUriPrefix)
> ------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-24625
> URL: https://issues.apache.org/jira/browse/CAMEL-24625
> Project: Camel
> Issue Type: Improvement
> Components: camel-platform-http
> Reporter: Federico Mariani
> Assignee: Federico Mariani
> Priority: Major
>
> *Use case:* building a path-based reverse proxy on platform-http — expose a
> backend under a prefix (e.g. {{/reverse-proxy/**}}) and forward to it
> ({{http://backend/**}}), stripping the prefix. This is the standard
> reverse-proxy shape (nginx {{location}}, Spring Cloud Gateway
> {{StripPrefix}}, Traefik {{StripPrefix}}, Envoy {{prefix_rewrite}}) and today
> requires manual header surgery:
> {code:java}
> from("platform-http:/reverse-proxy?matchOnUriPrefix=true")
> .setHeader(Exchange.HTTP_PATH,
> simple("${header.CamelHttpPath.substring(14)}")) // 14 == prefix length,
> duplicated by hand
> .to("http://backend?bridgeEndpoint=true")
> {code}
> camel-servlet, camel-jetty, camel-netty-http and camel-undertow do not need
> this — their consumers already make CamelHttpPath relative to the registered
> consumer path, so bridgeEndpoint=true alone does the right thing.
> platform-http (both the Vert.x and Spring Boot/camel-platform-http-starter
> engines) is the one HTTP consumer that always reports the full raw path.
> *Proposal:* add a {{stripUriPrefix}} consumer option (default {{false}}) to
> PlatformHttpEndpoint. When set, the matched consumer path is removed from
> CamelHttpPath (segment-boundary aware), so the reverse proxy above becomes:
> {code:java}
> from("platform-http:/reverse-proxy?matchOnUriPrefix=true&stripUriPrefix=true")
> .to("http://backend?bridgeEndpoint=true")
> {code}
> CamelHttpUri/CamelHttpUrl keep the full path. Default is {{false}} to avoid a
> breaking change (existing Vert.x routes rely on the full path); aligning the
> default with the other consumers is left to a future major version.
> *PR (core, Vert.x engine):* https://github.com/apache/camel/pull/26114
> A follow-up in apache/camel-spring-boot wires the same option into the Spring
> Boot platform-http engine (camel-platform-http-starter).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)