|
29 | 29 | from six.moves.urllib.parse import urlencode
|
30 | 30 |
|
31 | 31 | # Do not remove the httplib2 import
|
| 32 | +import json |
32 | 33 | import httplib2
|
33 | 34 | import logging
|
34 | 35 | import mock
|
@@ -456,6 +457,41 @@ def test_media_io_base_download(self):
|
456 | 457 | self.assertEqual(5, download._progress)
|
457 | 458 | self.assertEqual(5, download._total_size)
|
458 | 459 |
|
| 460 | + def test_media_io_base_download_custom_request_headers(self): |
| 461 | + self.request.http = HttpMockSequence([ |
| 462 | + ({'status': '200', |
| 463 | + 'content-range': '0-2/5'}, 'echo_request_headers_as_json'), |
| 464 | + ({'status': '200', |
| 465 | + 'content-range': '3-4/5'}, 'echo_request_headers_as_json'), |
| 466 | + ]) |
| 467 | + self.assertEqual(True, self.request.http.follow_redirects) |
| 468 | + |
| 469 | + self.request.headers['Cache-Control'] = 'no-store' |
| 470 | + |
| 471 | + download = MediaIoBaseDownload( |
| 472 | + fd=self.fd, request=self.request, chunksize=3) |
| 473 | + |
| 474 | + self.assertEqual(download._headers, {'Cache-Control':'no-store'}) |
| 475 | + |
| 476 | + status, done = download.next_chunk() |
| 477 | + |
| 478 | + result = self.fd.getvalue().decode('utf-8') |
| 479 | + |
| 480 | + # we abuse the internals of the object we're testing, pay no attention |
| 481 | + # to the actual bytes= values here; we are just asserting that the |
| 482 | + # header we added to the original request is sent up to the server |
| 483 | + # on each call to next_chunk |
| 484 | + |
| 485 | + self.assertEqual(json.loads(result), |
| 486 | + {"Cache-Control": "no-store", "range": "bytes=0-3"}) |
| 487 | + |
| 488 | + download._fd = self.fd = BytesIO() |
| 489 | + status, done = download.next_chunk() |
| 490 | + |
| 491 | + result = self.fd.getvalue().decode('utf-8') |
| 492 | + self.assertEqual(json.loads(result), |
| 493 | + {"Cache-Control": "no-store", "range": "bytes=51-54"}) |
| 494 | + |
459 | 495 | def test_media_io_base_download_handle_redirects(self):
|
460 | 496 | self.request.http = HttpMockSequence([
|
461 | 497 | ({'status': '200',
|
|
0 commit comments