Skip to content

Commit 8019f2f

Browse files
schweikertparthea
andauthored
fix: update content-length header for next page (#1404)
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 <[email protected]>
1 parent a0af9b1 commit 8019f2f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

googleapiclient/discovery.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ def methodNext(self, previous_request, previous_response):
12831283
body = model.deserialize(request.body)
12841284
body[pageTokenName] = nextPageToken
12851285
request.body = model.serialize(body)
1286+
request.body_size = len(request.body)
1287+
if "content-length" in request.headers:
1288+
del request.headers["content-length"]
12861289
logger.debug("Next page request body: %s %s" % (methodName, body))
12871290

12881291
return request

tests/test_discovery.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,9 @@ def test_next_successful_with_next_page_token_in_body(self):
21722172
next_request = logging.entries().list_next(request, {"nextPageToken": "123abc"})
21732173
body = JsonModel().deserialize(next_request.body)
21742174
self.assertEqual(body["pageToken"], "123abc")
2175+
# The body is changed, make sure that body_length is changed too (see
2176+
# github #1403)
2177+
self.assertEqual(next_request.body_size, len(next_request.body))
21752178

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

0 commit comments

Comments
 (0)