Skip to content

Commit

Permalink
fix: update content-length header for next page (#1404)
Browse files Browse the repository at this point in the history
The content-length header only gets updated at request object
initialization, so make sure we update it here after we modified the
body.

Fixes #1403

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
schweikert and parthea committed Jun 8, 2021
1 parent a0af9b1 commit 8019f2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions googleapiclient/discovery.py
Expand Up @@ -1283,6 +1283,9 @@ def methodNext(self, previous_request, previous_response):
body = model.deserialize(request.body)
body[pageTokenName] = nextPageToken
request.body = model.serialize(body)
request.body_size = len(request.body)
if "content-length" in request.headers:
del request.headers["content-length"]
logger.debug("Next page request body: %s %s" % (methodName, body))

return request
Expand Down
3 changes: 3 additions & 0 deletions tests/test_discovery.py
Expand Up @@ -2172,6 +2172,9 @@ def test_next_successful_with_next_page_token_in_body(self):
next_request = logging.entries().list_next(request, {"nextPageToken": "123abc"})
body = JsonModel().deserialize(next_request.body)
self.assertEqual(body["pageToken"], "123abc")
# The body is changed, make sure that body_length is changed too (see
# github #1403)
self.assertEqual(next_request.body_size, len(next_request.body))

def test_next_with_method_with_no_properties(self):
self.http = HttpMock(datafile("latitude.json"), {"status": "200"})
Expand Down

0 comments on commit 8019f2f

Please sign in to comment.