dataplaneapi icon indicating copy to clipboard operation
dataplaneapi copied to clipboard

Add a new HTTP Request Rule not checking if exists already

Open VladoPortos opened this issue 2 years ago • 1 comments

Hello,

I'm not sure if I'm doing something wrong but "POST /services/haproxy/configuration/http_request_rules" does not check if the rule already exists and keep doubling it...

I need to add: http-request set-header X-Forwarded-Proto https into specific backend.

The whole process looks like this:

  1. create the backed using version at the end of the call ( for some reason, I can't create a transaction where I create backend and add stuff into it... )
  2. create transaction and get ID
  3. add the header.
 curl -X POST --user admin:admin \
   -H "Content-Type: application/json" \
   -d '{"type": "set-header", "index": 0, "hdr_name": "X-Forwarded-Proto https"}' \
   "http://localhost:5555/v2/services/haproxy/configuration/http_request_rules?parent_type=backend&parent_name=some_backend&transaction_id=6835c700-f04e-4070-bbbc-2e970861ab45"

  1. add server to backend ( this does not duplicate, so its ok )
  2. commit the transaction.

Run it multiple time and the backend does not get duplicated, the server in backend does not get duplicated... the header keeps multiplying...

backend some_backend
  http-request set-header X-Forwarded-Proto https
  http-request set-header X-Forwarded-Proto https
  http-request set-header X-Forwarded-Proto https
  server server1 127.0.0.1:443 check ssl verify none

Is this a bug, or am I doing it wrong. There is a ton of option for the "Add a new HTTP Request Rule" but no explanation what is what.

EDIT: I have tried also just adding version= at the end without transaction and the effect is the same. Either I'm adding it wrong, or the check that should verify an already existing header is not working.

VladoPortos avatar Mar 02 '22 17:03 VladoPortos

This is because a configuration with multiple same http-request lines can be actually valid. They are evaluated in the order they are stated, and sometimes you can have two same http-request rules but in different positions and the end result is different.

mjuraga avatar May 04 '22 10:05 mjuraga