Skip to content

Commit 80da1ef

Browse files
Merge pull request #101 from eljobe/master
Stop stripping newlines from batch requests.
2 parents 63f5f3e + 30ecbd4 commit 80da1ef

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

googleapiclient/http.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,6 @@ def _serialize_request(self, request):
11201120
g.flatten(msg, unixfrom=False)
11211121
body = fp.getvalue()
11221122

1123-
# Strip off the \n\n that the MIME lib tacks onto the end of the payload.
1124-
if request.body is None:
1125-
body = body[:-2]
1126-
11271123
return status_line + body
11281124

11291125
def _deserialize_response(self, payload):

tests/test_http.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ def test_media_io_base_download_retries_5xx(self):
453453
Host: www.googleapis.com
454454
content-length: 0\r\n\r\n"""
455455

456+
NO_BODY_EXPECTED_GET = """GET /someapi/v1/collection/?foo=bar HTTP/1.1
457+
Content-Type: application/json
458+
MIME-Version: 1.0
459+
Host: www.googleapis.com\r\n\r\n"""
460+
456461

457462
RESPONSE = """HTTP/1.1 200 OK
458463
Content-Type: application/json
@@ -711,6 +716,20 @@ def test_serialize_request_no_body(self):
711716
s = batch._serialize_request(request).splitlines()
712717
self.assertEqual(NO_BODY_EXPECTED.splitlines(), s)
713718

719+
def test_serialize_get_request_no_body(self):
720+
batch = BatchHttpRequest()
721+
request = HttpRequest(
722+
None,
723+
None,
724+
'https://www.googleapis.com/someapi/v1/collection/?foo=bar',
725+
method='GET',
726+
body=None,
727+
headers={'content-type': 'application/json'},
728+
methodId=None,
729+
resumable=None)
730+
s = batch._serialize_request(request).splitlines()
731+
self.assertEqual(NO_BODY_EXPECTED_GET.splitlines(), s)
732+
714733
def test_deserialize_response(self):
715734
batch = BatchHttpRequest()
716735
resp, content = batch._deserialize_response(RESPONSE)

0 commit comments

Comments
 (0)