This is an automated email from the ASF dual-hosted git repository.

elserj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix-queryserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 6bfb0b9  PHOENIX-6459 Try to use a Session to pass along any cookies 
the serve… (#60)
6bfb0b9 is described below

commit 6bfb0b94c37a999fc3e4344e6b8d965083d6d1d4
Author: Josh Elser <[email protected]>
AuthorDate: Thu May 6 12:07:17 2021 -0400

    PHOENIX-6459 Try to use a Session to pass along any cookies the serve… (#60)
    
    The Requests documentation also alludes to performance benefit due to
    leaving the existing connection open (rather than re-connecting each time)
    
      https://docs.python-requests.org/en/master/user/advanced/#session-objects
---
 python-phoenixdb/phoenixdb/avatica/client.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/python-phoenixdb/phoenixdb/avatica/client.py 
b/python-phoenixdb/phoenixdb/avatica/client.py
index a1f502c..5c96586 100644
--- a/python-phoenixdb/phoenixdb/avatica/client.py
+++ b/python-phoenixdb/phoenixdb/avatica/client.py
@@ -149,6 +149,7 @@ class AvaticaClient(object):
         self.auth = auth
         self.verify = verify
         self.connection = None
+        self.session = None
 
     def connect(self):
         """This method used to open a persistent TCP connection
@@ -160,20 +161,28 @@ class AvaticaClient(object):
         pass
 
     def _post_request(self, body, headers):
+        # Create the session if we haven't before
+        if not self.session:
+            logger.debug("Creating a new Session")
+            self.session = requests.Session()
+            self.session.headers.update(headers)
+            self.session.stream = True
+            if self.auth is not None:
+                self.session.auth = self.auth
+
         retry_count = self.max_retries
         while True:
-            logger.debug("POST %s %r %r", self.url.geturl(), body, headers)
+            logger.debug("POST %s %r %r", self.url.geturl(), body, 
self.session.headers)
 
-            requestArgs = {'data': body, 'stream': True, 'headers': headers}
-
-            if self.auth is not None:
-                requestArgs.update(auth=self.auth)
+            requestArgs = {'data': body}
 
+            # Setting verify on the Session is not the same as setting it
+            # as a request arg
             if self.verify is not None:
                 requestArgs.update(verify=self.verify)
 
             try:
-                response = requests.request('post', self.url.geturl(), 
**requestArgs)
+                response = self.session.post(self.url.geturl(), **requestArgs)
 
             except requests.HTTPError as e:
                 if retry_count > 0:

Reply via email to