Change GET to POST if URI is too long. Fixes issue #96.
Reviewed in http://codereview.appspot.com/6454092/.
diff --git a/apiclient/http.py b/apiclient/http.py
index 3c38bc9..753dd09 100644
--- a/apiclient/http.py
+++ b/apiclient/http.py
@@ -48,6 +48,8 @@
 
 DEFAULT_CHUNK_SIZE = 512*1024
 
+MAX_URI_LENGTH = 4000
+
 
 class MediaUploadProgress(object):
   """Status of a resumable upload."""
@@ -646,6 +648,19 @@
     else:
       if 'content-length' not in self.headers:
         self.headers['content-length'] = str(self.body_size)
+      # If the request URI is too long then turn it into a POST request.
+      if len(self.uri) > MAX_URI_LENGTH and self.method == 'GET':
+        self.method = 'POST'
+        self.headers['x-http-method-override'] = 'GET'
+        self.headers['content-type'] = 'application/x-www-form-urlencoded'
+        parsed = urlparse.urlparse(self.uri)
+        self.uri = urlparse.urlunparse(
+            (parsed.scheme, parsed.netloc, parsed.path, parsed.params, None,
+             None)
+            )
+        self.body = parsed.query
+        self.headers['content-length'] = str(len(self.body))
+
       resp, content = http.request(self.uri, self.method,
                                    body=self.body,
                                    headers=self.headers)