Skip to content

Commit

Permalink
Dropping extra headers from transmit_next_chunk().
Browse files Browse the repository at this point in the history
It appears that **only** the initiate() request requires them.
  • Loading branch information
dhermes committed Apr 24, 2017
1 parent 89415d1 commit fd47338
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 8 additions & 6 deletions google/resumable_media/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ class ResumableUpload(_UploadBase):
upload_url (str): The URL where the resumable upload will be initiated.
chunk_size (int): The size of each chunk used to upload the resource.
headers (Optional[Mapping[str, str]]): Extra headers that should
be sent with the :meth:`initiate` request and each
:meth:`transmit_next_chunk` request, e.g. headers for encrypted
data. These **will not** be sent with a :meth:`recover` request.
be sent with the :meth:`initiate` request, e.g. headers for
encrypted data. These **will not** be sent with
:meth:`transmit_next_chunk` or :meth:`recover` requests.
Raises:
ValueError: If ``chunk_size`` is not a multiple of
Expand Down Expand Up @@ -403,7 +403,9 @@ def _prepare_request(self):
will (almost) certainly not be network I/O.
Returns:
Tuple[bytes, dict]: The payload and headers for the request.
Tuple[bytes, dict]: The payload and headers for the request. The
headers **do not** incorporate the ``_headers`` on the
current instance.
Raises:
ValueError: If the current upload has finished.
Expand Down Expand Up @@ -437,7 +439,6 @@ def _prepare_request(self):
_CONTENT_TYPE_HEADER: self._content_type,
_helpers.CONTENT_RANGE_HEADER: content_range,
}
headers.update(self._headers)
return payload, headers

def _make_invalid(self):
Expand Down Expand Up @@ -560,7 +561,8 @@ def _prepare_recover_request(self):
the upload can end up :attr:`invalid` is if it has been initiated.
Returns:
dict: The headers for the request.
dict: The headers for the request (they **do not** incorporate the
``_headers`` on the current instance).
Raises:
ValueError: If the current upload is not in an invalid state.
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,12 @@ def test__prepare_request_success_with_headers(self):
new_headers = self._prepare_request_helper(headers)
assert new_headers is not headers
expected_headers = {
u'cannot': u'touch this',
u'content-range': u'bytes 0-32/33',
u'content-type': BASIC_CONTENT,
}
assert new_headers == expected_headers
# Make sure the ``_headers`` are not incorporated.
assert u'cannot' not in new_headers

def test__make_invalid(self):
upload = upload_mod.ResumableUpload(RESUMABLE_URL, ONE_MB)
Expand Down Expand Up @@ -649,6 +650,19 @@ def test__prepare_recover_request(self):
# Make sure headers are untouched.
assert upload._headers == {}

def test__prepare_recover_request_with_headers(self):
headers = {u'lake': u'ocean'}
upload = upload_mod.ResumableUpload(
RESUMABLE_URL, ONE_MB, headers=headers)
upload._invalid = True

new_headers = upload._prepare_recover_request()
assert new_headers == {u'content-range': u'bytes */*'}
# Make sure the ``_headers`` are not incorporated.
assert u'lake' not in new_headers
# Make sure headers are untouched.
assert upload._headers == {u'lake': u'ocean'}

def test__process_recover_response_bad_status(self):
upload = upload_mod.ResumableUpload(RESUMABLE_URL, ONE_MB)
upload._invalid = True
Expand Down

0 comments on commit fd47338

Please sign in to comment.