How can you force HAProxy server affinity with curl?
With curl version 7.58 I've tried:
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
I'm still getting round-robin, first-connection load balancing:
HTTP/1.1 200 Connection established
set-cookie: SRV_ID="172.21.0.3"; path=/
HTTP/1.1 200 OK
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Sat, 16 Nov 2019 22:05:22 GMT
ETag: W/"86-77S8g6gXGJd5i+Emjsb0b9sIcac"
Server: nginx
set-cookie: sails.sid=s%3AC1VtUY_GI...HsNx7LDg; Path=/; HttpOnly
Vary: Accept-Encoding
Connection: keep-alive
HAProxy 2.0.8 relevant backend configuration:
backend http-backend
mode http
balance roundrobin
default-server inter 2s fastinter 2s downinter 2s fall 3 rise 2
cookie SRV_ID insert
server container-172-21-0-2 172.21.0.2:3000 cookie \"172.21.0.2\" check
server container-172-21-0-3 172.21.0.3:3000 cookie \"172.21.0.3\" check
I'm able to save and send saved cookies, and I can edit the cookie-jar file for the effect I'm looking for, but how to craft the curl command in one line?
curl -b cookies.txt -c cookies.txt -x localhost:3001 http://scooterlabs.com/echo
Cookites.txt contents:
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
scooterlabs.com FALSE / FALSE 0 SRV_ID "172.21.0.2"
Replace
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
with
curl -I \
--proxy-header "Cookie: SRV_ID=\"172.0.0.2\"" \
-x localhost:3001 \
https://postman-echo.com/headers
Notice the extra quotes around the value of SRV_ID. This must match the string between 'cookie' and 'check' in cookie \"172.21.0.2\" check
.