Skip to content

Commit

Permalink
Remove unnecessary parsing of mime headers in HttpRequest.__init__ (#467
Browse files Browse the repository at this point in the history
)

Fixes #284
  • Loading branch information
xmedeko authored and Jon Wayne Parrott committed Jan 19, 2018
1 parent 6436741 commit b86bfc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
5 changes: 0 additions & 5 deletions googleapiclient/http.py
Expand Up @@ -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
Expand Down Expand Up @@ -769,10 +768,6 @@ def __init__(self, http, postproc, uri,
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 '')

Expand Down
26 changes: 20 additions & 6 deletions tests/test_http.py
Expand Up @@ -176,6 +176,10 @@ def request(self, *args, **kwargs):
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):
Expand Down Expand Up @@ -240,16 +244,12 @@ def test_media_inmemory_upload(self):
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='{}',
Expand All @@ -258,7 +258,7 @@ def _postproc(*kwargs):
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"'},
Expand Down Expand Up @@ -808,6 +808,20 @@ def test_unicode(self):
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(
Expand Down

0 comments on commit b86bfc9

Please sign in to comment.