Repository: googleapis/google-api-python-client

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.



Discussion:

Resolving patch:
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
--- 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 @@ 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 '')
 


Test patch:
diff --git a/tests/test_http.py b/tests/test_http.py
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -172,6 +172,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):
@@ -236,16 +240,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='{}',
@@ -254,7 +254,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"'},
@@ -804,6 +804,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(