Commits

codingtony committed d5f9365 Merge
  • Participants
  • Parent commits d5527ce, ab128e0

Comments (0)

Files changed (1)

File rhodecode/lib/middleware/simplegit.py

 import re
 import logging
 import traceback
-
+import gzip
+from StringIO import StringIO 
 from dulwich import server as dulserver
 
+class GzipAwareMiddleware(object):
+    def __init__(self,app):
+        self.app = app
+        
+    def __call__(self,environ,start_response):
+        if 'gzip' in environ.get('HTTP_CONTENT_ENCODING', ''):
+            log.debug("HTTP_CONTENT_ENCODING=gzip found in request header")
+            body = environ['wsgi.input'].read()
+            gzipper = gzip.GzipFile(fileobj=StringIO(body)) 
+            environ['wsgi.input']=gzipper
+            del environ['HTTP_CONTENT_ENCODING']
+            # Could gunzip and calculate the length...
+            del environ['CONTENT_LENGTH']
+        return self.app(environ,start_response)
 
 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler):
 
         _d = {'/' + repo_name: Repo(repo_path)}
         backend = dulserver.DictBackend(_d)
         gitserve = HTTPGitApplication(backend)
-
-        return gitserve
+        
+        return GzipAwareMiddleware(gitserve); 
 
     def __get_repository(self, environ):
         """