From 787029d4cb9257b3d885c933a972d033d816a9a1 Mon Sep 17 00:00:00 2001 From: Matt Kemp Date: Fri, 24 Oct 2014 23:52:52 +0000 Subject: [PATCH] Ensure session stickiness when using a load balanced configuration. --- src/lib/Bcfg2/Client/Proxy.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/Bcfg2/Client/Proxy.py b/src/lib/Bcfg2/Client/Proxy.py index 679b4c52b5..dd34547d86 100644 --- a/src/lib/Bcfg2/Client/Proxy.py +++ b/src/lib/Bcfg2/Client/Proxy.py @@ -242,6 +242,7 @@ def __init__(self, key=None, cert=None, ca=None, self.scns = scns self.timeout = timeout self.protocol = protocol + self.cookie = None def make_connection(self, host): host, self._extra_headers = self.get_host_info(host)[0:2] @@ -258,6 +259,9 @@ def request(self, host, handler, request_body, verbose=0): try: conn = self.send_request(host, handler, request_body, False) response = conn.getresponse() + if not self.cookie: + self.cookie = response.getheader('Set-Cookie') + print self.cookie errcode = response.status errmsg = response.reason headers = response.msg @@ -285,6 +289,8 @@ def send_request(self, host, handler, request_body, debug): xmlrpclib.Transport.send_request(self, conn, handler, request_body) self.send_host(conn, host) self.send_user_agent(conn) + if self.cookie: + conn.putheader('Cookie', self.cookie) self.send_content(conn, request_body) return conn # pylint: enable=E1101