Browse Source

Merged in cagriulas/python-keycloak/persistent_requests_session (pull request #23)

Make requests' Session persistent in ConnectionManager

Approved-by: Marcos Pereira <marcospereira.mpj@gmail.com>
pull/12/head
Çağrı Ulaş 6 years ago
committed by Marcos Pereira
parent
commit
47e2692841
  1. 9
      keycloak/connection.py

9
keycloak/connection.py

@ -45,6 +45,7 @@ class ConnectionManager(object):
self._headers = headers self._headers = headers
self._timeout = timeout self._timeout = timeout
self._verify = verify self._verify = verify
self._s = requests.Session()
@property @property
def base_url(self): def base_url(self):
@ -134,7 +135,7 @@ class ConnectionManager(object):
""" """
try: try:
return requests.get(urljoin(self.base_url, path),
return self._s.get(urljoin(self.base_url, path),
params=kwargs, params=kwargs,
headers=self.headers, headers=self.headers,
timeout=self.timeout, timeout=self.timeout,
@ -154,7 +155,7 @@ class ConnectionManager(object):
HttpError: Can't connect to server. HttpError: Can't connect to server.
""" """
try: try:
return requests.post(urljoin(self.base_url, path),
return self._s.post(urljoin(self.base_url, path),
params=kwargs, params=kwargs,
data=data, data=data,
headers=self.headers, headers=self.headers,
@ -175,7 +176,7 @@ class ConnectionManager(object):
HttpError: Can't connect to server. HttpError: Can't connect to server.
""" """
try: try:
return requests.put(urljoin(self.base_url, path),
return self._s.put(urljoin(self.base_url, path),
params=kwargs, params=kwargs,
data=data, data=data,
headers=self.headers, headers=self.headers,
@ -196,7 +197,7 @@ class ConnectionManager(object):
HttpError: Can't connect to server. HttpError: Can't connect to server.
""" """
try: try:
return requests.delete(urljoin(self.base_url, path),
return self._s.delete(urljoin(self.base_url, path),
params=kwargs, params=kwargs,
headers=self.headers, headers=self.headers,
timeout=self.timeout, timeout=self.timeout,

Loading…
Cancel
Save