8000 feat: include API response headers in 'Last Response' (#528) · dialex-com/twilio-python@203072b · GitHub
[go: up one dir, main page]

Skip to content

Commit 203072b

Browse files
author
childish-sambino
authored
feat: include API response headers in 'Last Response' (twilio#528)
The default HTTP client stores 'Last Request' and 'Last Response' information for access to more data about the raw API request/response. The response object did not contain the headers until now.
1 parent cb11802 commit 203072b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

twilio/http/http_client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import logging
2+
13
from requests import Request, Session, hooks
24
from requests.adapters import HTTPAdapter
3-
5+
from twilio.compat import urlencode
46
from twilio.http import HttpClient
5-
from twilio.http.response import Response
67
from twilio.http.request import Request as TwilioRequest
7-
import logging
8-
from twilio.compat import urlencode
8+
from twilio.http.response import Response
99

1010
_logger = logging.getLogger('twilio.http_client')
1111

@@ -14,7 +14,9 @@ class TwilioHttpClient(HttpClient):
1414
"""
1515
General purpose HTTP Client for interacting with the Twilio API
1616
"""
17-
def __init__(self, pool_connections=True, request_hooks=None, timeout=None, logger=_logger, proxy=None, max_retries=None):
17+
18+
def __init__(self, pool_connections=True, request_hooks=None, timeout=None, logger=_logger, proxy=None,
19+
max_retries=None):
1820
"""
1921
Constructor for the TwilioHttpClient
2022
@@ -96,6 +98,6 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
9698
method=method, status=response.status_code, text=response.text)
9799
)
98100

99-
self.last_response = Response(int(response.status_code), response.text)
101+
self.last_response = Response(int(response.status_code), response.text, response.headers)
100102

101103
return self.last_response

twilio/http/response.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class Response(object):
2-
"""
3-
4-
"""
5-
def __init__(self, status_code, text):
2+
def __init__(self, status_code, text, headers=None):
63
self.content = text
4+
self.headers = headers
75
self.cached = False
86
self.status_code = status_code
97
self.ok = self.status_code < 400

0 commit comments

Comments
 (0)
0