Haproxy dynamic backend matching request header - header

I am trying to find a solution for a problem I have with haproxy. Is something like this possible with haproxy if so can someone help with the right syntax or documentation?
Header: key=value
acl custom_header key=value
use backend value
backend value
server something.value.com
The term value should be a var or place holder so I can match particular backend when the request has a particular value for the key

You can use the variable in the use backend directive.
Here is a snippet the full answer is here.
https://stackoverflow.com/a/61931107/6778826
frontend fe1
...
use_backend %[req.hdr(key),lower]
backend value
server something.value.com

Related

Ambassador Mapping Rewrite Needs Original URL In Header

I'm using Ambassador Mappings created through a Helm chart in order to rewrite and forward a web request. The client has requested that we include the originally requested URL in a header when we forward the request.
Based on documentation, it looks like there are only two dynamic values I can set: %DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT% and %PROTOCOL%, neither of which seems to solve my issue.
Are there any ways for me to set this header properly through an Ambassador mapping?
Thanks!
So I think we've found the solution. If you use Envoy's syntax and make sure that is forwarded through, you can use their REQ() function, to get the authority and path, to construct the URL. For example:
http://%REQ(:authority)%%REQ(:path)%
Here is the documentation for all of the possibilities you can use with Envoy through Ambassador's mapping: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#custom-request-response-headers

Redirect and change the request method and content

I was reading the mod_rewrite documentation but haven't found an example to match the following scenario.
The use will try to use a GET request to /api/getCars.
On apache I need to change this request to POST method, to a different server, like https://internal_server/getAllCars, and I need to add some content on the body of this request and send it as x-www-form-urlencoded Content Type.
Which apache module do I have to use to achieve this behavior.
Can anybody provide any example?
Thanks

Is there any way to get the original Host header value?

This article says:
With these added headers, Cloudflare passes on all HTTP headers as is
from the client to the origin.
However, there doesn't appear to be a standard way to get the Host from the original request.
Is there a way to do this, either via standard options or enterprise option?

Rewriting the response header in traefik

I have a kubernetes cluster and I am using traefik ingress controller to route traffic to deployments inside the kubenetes cluster.
I am able to use ingress.kubernetes.io/rewrite-target annotation to change the incoming request path to the one expected by the backend.
For example : /star is transformed to /trek by the rewrite target annotation and the request gets routed to /trek and backend processing is successful.
What I want to know is if there is a way to change response header so that /trek gets changed back to /star?
Did you get an answer to this? It looks like similar functionality is available in Apache Traffic Server: https://docs.trafficserver.apache.org/en/latest/admin-guide/plugins/header_rewrite.en.html, but would be good to have it in traefik
The functionality that does this is modifiers and specifically ReplacePath. Here is a similar answer with some examples.

Conditional Configuration in Apache based on HTTP Headers

I want to do some conditional Configuration in Apache based on one particular HTTP request header.
For eg.,
Enable HTTP Digest Authentication for a set of Client IP Address and enable HTTP Basic Authentication for another set of Client IP Address.
For dynamically changing the configuration I am using .htaccess but i am not able to find a way to read the Client IP Address in the Configuration (.htaccess) and apply condition based on the IP Address.
I tried using mod header but i couldn't figure out the way. Please provide me some direction in this regards
Would using the tags fix your problem ?
https://blogs.apache.org/httpd/entry/new_in_httpd_2_4