Skip to content

Commit b86bfc9

Browse files
xmedekoJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Remove unnecessary parsing of mime headers in HttpRequest.__init__ (googleapis#467)
Fixes googleapis#284
1 parent 6436741 commit b86bfc9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

googleapiclient/http.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
from oauth2client import _helpers as util
6464

6565
from googleapiclient import _auth
66-
from googleapiclient import mimeparse
6766
from googleapiclient.errors import BatchError
6867
from googleapiclient.errors import HttpError
6968
from googleapiclient.errors import InvalidChunkSizeError
@@ -769,10 +768,6 @@ def __init__(self, http, postproc, uri,
769768
self.response_callbacks = []
770769
self._in_error_state = False
771770

772-
# Pull the multipart boundary out of the content-type header.
773-
major, minor, params = mimeparse.parse_mime_type(
774-
self.headers.get('content-type', 'application/json'))
775-
776771
# The size of the non-media part of the request.
777772
self.body_size = len(self.body or '')
778773

tests/test_http.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def request(self, *args, **kwargs):
176176
def datafile(filename):
177177
return os.path.join(DATA_DIR, filename)
178178

179+
def _postproc_none(*kwargs):
180+
pass
181+
182+
179183
class TestUserAgent(unittest.TestCase):
180184

181185
def test_set_user_agent(self):
@@ -240,16 +244,12 @@ def test_media_inmemory_upload(self):
240244
self.assertEqual(6, media.size())
241245

242246
def test_http_request_to_from_json(self):
243-
244-
def _postproc(*kwargs):
245-
pass
246-
247247
http = build_http()
248248
media_upload = MediaFileUpload(
249249
datafile('small.png'), chunksize=500, resumable=True)
250250
req = HttpRequest(
251251
http,
252-
_postproc,
252+
_postproc_none,
253253
'http://example.com',
254254
method='POST',
255255
body='{}',
@@ -258,7 +258,7 @@ def _postproc(*kwargs):
258258
resumable=media_upload)
259259

260260
json = req.to_json()
261-
new_req = HttpRequest.from_json(json, http, _postproc)
261+
new_req = HttpRequest.from_json(json, http, _postproc_none)
262262

263263
self.assertEqual({'content-type':
264264
'multipart/related; boundary="---flubber"'},
@@ -808,6 +808,20 @@ def test_unicode(self):
808808
self.assertEqual(method, http.method)
809809
self.assertEqual(str, type(http.method))
810810

811+
def test_empty_content_type(self):
812+
"""Test for #284"""
813+
http = HttpMock(None, headers={'status': 200})
814+
uri = u'https://www.googleapis.com/someapi/v1/upload/?foo=bar'
815+
method = u'POST'
816+
request = HttpRequest(
817+
http,
818+
_postproc_none,
819+
uri,
820+
method=method,
821+
headers={'content-type': ''})
822+
request.execute()
823+
self.assertEqual('', http.headers.get('content-type'))
824+
811825
def test_no_retry_connection_errors(self):
812826
model = JsonModel()
813827
request = HttpRequest(

0 commit comments

Comments
 (0)