Repository: google/google-api-python-client (python)

Issue:
HttpRequest.__init__ useless mimeparse
Hi,
the code in the `HttpRequest.__init__` is useless:

``` python
    # Pull the multipart boundary out of the content-type header.
    major, minor, params = mimeparse.parse_mime_type(
        self.headers.get('content-type', 'application/json'))
```

And it prevents from `storage.insert` creating explicit dirs without content-type. I.e. this code pass only with the above code removed:

``` python
    api = googleapiclient.discovery.build('storage', 'v1', credentials=credentials)
    media = googleapiclient.http.MediaIoBaseUpload(io.BytesIO(b''), '')
    resp = api.objects().insert(bucket=bucket, name='testdir/', media_body=media).execute()
```

BTW similar code with empty contentType works on the .NET client, too.


Pull request:
HttpRequest.__init__ remove useless mimeparse
Fix #284

Patch:
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index ee8d6e3c3..d492abac0 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -63,7 +63,6 @@ except ImportError:
   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 @@ class HttpRequest(object):
     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 '')
 


Test patch:
diff --git a/tests/test_http.py b/tests/test_http.py
index 2109af77a..f33740144 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -176,6 +176,10 @@ DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
 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 @@ class TestMediaUpload(unittest.TestCase):
     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 @@ class TestMediaUpload(unittest.TestCase):
         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 @@ class TestHttpRequest(unittest.TestCase):
     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(