ACL – How to use Haproxy routing traffic (reverse proxy) based on the request main body

I am trying to route the following request to the appropriate server based on the URL identified in the POST body below. I hope to achieve this goal by using HAProxy’s reverse proxy.

For example. I want to direct all requests to HAProxy instead of letting HAProxy check whether certain values ​​exist in the POST body (e.g. the notification URL value “pingpong”), if this is the case, please route the traffic to I will specify the endopint configuration.

POST /someURL/file.jsp HTTP/1.1
Host: 10.43.90.190:80
Content-Type: application/json
Connection: keep-alive
Accept: */*
Content-Length: 256

{"Info": {"groupName":"thisgroup1 ","Id":"M1234R456","id2":"TUP1234",
"countryCode":"USA","carrierCode":"USAIC","e164Address":"123456768789",
"notificationURL":"http://www.pingpong.com/notify",
"timestamp":"2014-03-04T17:33:30.000Z"}}

Is there a way to use acl to search for the content “pingpong” in the request body, and based on this value, I will route it appropriately?

Thank you!

This can be done using a simple access control list (ACL). However, in Haproxy 1.0( Before October 2015), this was not possible. You can include this option in your front end:

The option http-buffer-request

This option enables Haproxy You can access the body. Then you can use req.body to access the body. Example:

frontend http-in
bind *:80
option http- buffer-request
acl redirect_pingpong req.body -m reg [insert your regular expression here]
use_backend pingpong_backend if redirect_pingpong

default_backend web_bk

Then continue to define Your backend.

More information about accessing body content can be found here, and information about ACLs can be found here.

Me Trying to route the following request to the appropriate server based on the URL identified in the body of the POST below. I hope to achieve this by using the reverse proxy of HAProxy.

For example. I want to route all requests Directed to HAProxy, instead of letting HAProxy check whether there are certain values ​​in the POST body (such as the notification URL value “pingpong”), if this is the case, please route the traffic to the endopint configuration I will specify.

< p>

POST /someURL/file.jsp HTTP/1.1
Host: 10.43.90.190:80
Content-Type: application/json
Connection: keep-alive
Accept: */*
Content-Length: 256

{"Info": {"groupName":"thisgroup1","Id":"M1234R456","id2":"TUP1234",
"countryCode":"USA","carrierCode":"USAIC ","e164Address":"123456768789",
"notificationURL":"http://www.pingpong.com/notify",
"timestamp":"2014-03-04T17: 33:30.000Z"}}

Is there a way to use acl to search for the content “pingpong” in the request body, and based on this value, I will route it appropriately?

Thank you!

This can be done using a simple access control list (ACL). However, before Haproxy 1.0 (October 2015), this was not possible , You can include this option in your front end:

option http-buffer-request

This option allows Haproxy to access the body. Then you can use req.body to Access the body. Example:

frontend http-in
bind *:80
option http-buffer-request
acl redirect_pingpong req.body -m reg [insert your regular expression here]
use_backend pingpong_backend if redirect_pingpong

default_backend web_bk

Then continue to define your backend.

More information about accessing the body content can be found here, and information about ACLs can be found here.

Leave a Comment

Your email address will not be published.