caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.84k stars 3.98k forks source link

`lb_policy` for a subset of the path #5598

Open huluxia opened 1 year ago

huluxia commented 1 year ago

Why can't add lb_policy hash as custom in caddy

francislavoie commented 1 year ago

You're gonna have to be more specific. That's way too vague. Please explain in detail what you mean. Show some examples.

huluxia commented 1 year ago

You're gonna have to be more specific. That's way too vague. Please explain in detail what you mean. Show some examples.

Can the lb_policy of reverse_proxy customize hash calculation, for example, can I perform uri_hash calculation based on the specified part of uri instead of the entire uri, such as /path/0 and /path/1, my needs are as long as /path is the same, so whether it is / path/0 and /path/1 next time the same request, go to the backend server allocated last time

francislavoie commented 1 year ago

Interesting. That's not currently possible, but we could implement a policy that takes placeholders as input to be replaced. You could pair it with a path_regexp matcher to pull out the bits of the path you need. But if you use a matcher, you have to take care of handling the base case where it doesn't match which can be tricky.

In the short term, I recommend writing a plugin that does what you need. LB policies are pluggable, so you can make it do exactly what you need yourself. See https://caddyserver.com/docs/extending-caddy, existing policy modules are defined here https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/selectionpolicies.go

huluxia commented 1 year ago

thank you!Hope caddy can add this feature in the future.

armadi1809 commented 5 months ago

@francislavoie are we still interested in implementing this?

francislavoie commented 5 months ago

Sure, we can add it. I'm not sure how it'll look yet so if you make a prototype we can iterate on it 👍 thanks!