Remove unnecessary parsing of mime headers in HttpRequest.__init__ (#467)
Fixes #284
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index ee8d6e3..d492aba 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -63,7 +63,6 @@
from oauth2client import _helpers as util
from googleapiclient import _auth
-from googleapiclient import mimeparse
from googleapiclient.errors import BatchError
from googleapiclient.errors import HttpError
from googleapiclient.errors import InvalidChunkSizeError
@@ -769,10 +768,6 @@
self.response_callbacks = []
self._in_error_state = False
- # Pull the multipart boundary out of the content-type header.
- major, minor, params = mimeparse.parse_mime_type(
- self.headers.get('content-type', 'application/json'))
-
# The size of the non-media part of the request.
self.body_size = len(self.body or '')
diff --git a/tests/test_http.py b/tests/test_http.py
index 2109af7..f337401 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -176,6 +176,10 @@
def datafile(filename):
return os.path.join(DATA_DIR, filename)
+def _postproc_none(*kwargs):
+ pass
+
+
class TestUserAgent(unittest.TestCase):
def test_set_user_agent(self):
@@ -240,16 +244,12 @@
self.assertEqual(6, media.size())
def test_http_request_to_from_json(self):
-
- def _postproc(*kwargs):
- pass
-
http = build_http()
media_upload = MediaFileUpload(
datafile('small.png'), chunksize=500, resumable=True)
req = HttpRequest(
http,
- _postproc,
+ _postproc_none,
'http://example.com',
method='POST',
body='{}',
@@ -258,7 +258,7 @@
resumable=media_upload)
json = req.to_json()
- new_req = HttpRequest.from_json(json, http, _postproc)
+ new_req = HttpRequest.from_json(json, http, _postproc_none)
self.assertEqual({'content-type':
'multipart/related; boundary="---flubber"'},
@@ -808,6 +808,20 @@
self.assertEqual(method, http.method)
self.assertEqual(str, type(http.method))
+ def test_empty_content_type(self):
+ """Test for #284"""
+ http = HttpMock(None, headers={'status': 200})
+ uri = u'https://www.googleapis.com/someapi/v1/upload/?foo=bar'
+ method = u'POST'
+ request = HttpRequest(
+ http,
+ _postproc_none,
+ uri,
+ method=method,
+ headers={'content-type': ''})
+ request.execute()
+ self.assertEqual('', http.headers.get('content-type'))
+
def test_no_retry_connection_errors(self):
model = JsonModel()
request = HttpRequest(