Merge pull request #101 from eljobe/master
Stop stripping newlines from batch requests.
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index f63d33e..f272ba8 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -1120,10 +1120,6 @@
g.flatten(msg, unixfrom=False)
body = fp.getvalue()
- # Strip off the \n\n that the MIME lib tacks onto the end of the payload.
- if request.body is None:
- body = body[:-2]
-
return status_line + body
def _deserialize_response(self, payload):
diff --git a/tests/test_http.py b/tests/test_http.py
index 85eea8e..c12c7b1 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -453,6 +453,11 @@
Host: www.googleapis.com
content-length: 0\r\n\r\n"""
+NO_BODY_EXPECTED_GET = """GET /someapi/v1/collection/?foo=bar HTTP/1.1
+Content-Type: application/json
+MIME-Version: 1.0
+Host: www.googleapis.com\r\n\r\n"""
+
RESPONSE = """HTTP/1.1 200 OK
Content-Type: application/json
@@ -711,6 +716,20 @@
s = batch._serialize_request(request).splitlines()
self.assertEqual(NO_BODY_EXPECTED.splitlines(), s)
+ def test_serialize_get_request_no_body(self):
+ batch = BatchHttpRequest()
+ request = HttpRequest(
+ None,
+ None,
+ 'https://www.googleapis.com/someapi/v1/collection/?foo=bar',
+ method='GET',
+ body=None,
+ headers={'content-type': 'application/json'},
+ methodId=None,
+ resumable=None)
+ s = batch._serialize_request(request).splitlines()
+ self.assertEqual(NO_BODY_EXPECTED_GET.splitlines(), s)
+
def test_deserialize_response(self):
batch = BatchHttpRequest()
resp, content = batch._deserialize_response(RESPONSE)