Skip to content

Commit f978789

Browse files
pR0Psjborean93
authored andcommitted
Set SanitizedResponse content to bytes instead of string
The `content` property of a `Response` object is expected to always be bytes (the `text` property should be a string). This change fixes an issue where consumers of the library that were returned a `SanitizedResponse` object could fail because they expected the `content` attribute of it to be bytes instead of a string. Signed-off-by: Carey Metcalfe <[email protected]>
1 parent 84e052b commit f978789

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: requests_gssapi/gssapi_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, response):
5454
self.connection = response.connection
5555
self._content_consumed = True
5656

57-
self._content = ""
57+
self._content = b""
5858
self.cookies = cookiejar_from_dict({})
5959
self.headers = CaseInsensitiveDict()
6060
self.headers['content-length'] = '0'

Diff for: test_requests_gssapi.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_authenticate_user(self):
164164
response.headers = {'www-authenticate': b64_negotiate_token}
165165
response.status_code = 401
166166
response.connection = connection
167-
response._content = ""
167+
response._content = b""
168168
response.raw = raw
169169
auth = requests_gssapi.HTTPKerberosAuth()
170170
r = auth.authenticate_user(response)
@@ -201,7 +201,7 @@ def test_handle_401(self):
201201
response.headers = {'www-authenticate': b64_negotiate_token}
202202
response.status_code = 401
203203
response.connection = connection
204-
response._content = ""
204+
response._content = b""
205205
response.raw = raw
206206
auth = requests_gssapi.HTTPKerberosAuth()
207207
r = auth.handle_401(response)
@@ -375,7 +375,8 @@ def test_handle_response_500_mutual_auth_required_failure(self):
375375
self.assertEqual(r.url, response_500.url)
376376
self.assertEqual(r.reason, response_500.reason)
377377
self.assertEqual(r.connection, response_500.connection)
378-
self.assertEqual(r.content, '')
378+
self.assertEqual(r.content, b"")
379+
self.assertEqual(r.text, "")
379380
self.assertNotEqual(r.cookies, response_500.cookies)
380381

381382
self.assertFalse(fail_resp.called)
@@ -436,7 +437,7 @@ def test_handle_response_401(self):
436437
response.headers = {'www-authenticate': b64_negotiate_token}
437438
response.status_code = 401
438439
response.connection = connection
439-
response._content = ""
440+
response._content = b""
440441
response.raw = raw
441442

442443
auth = requests_gssapi.HTTPKerberosAuth()
@@ -482,7 +483,7 @@ def connection_send(self, *args, **kwargs):
482483
response.headers = {'www-authenticate': b64_negotiate_token}
483484
response.status_code = 401
484485
response.connection = connection
485-
response._content = ""
486+
response._content = b""
486487
response.raw = raw
487488

488489
auth = requests_gssapi.HTTPKerberosAuth()
@@ -534,7 +535,7 @@ def test_delegation(self):
534535
response.headers = {'www-authenticate': b64_negotiate_token}
535536
response.status_code = 401
536537
response.connection = connection
537-
response._content = ""
538+
response._content = b""
538539
response.raw = raw
539540
auth = requests_gssapi.HTTPKerberosAuth(service="HTTP",
540541
delegate=True)

0 commit comments

Comments
 (0)