1. Randall Leeds
  2. restkit

Commits

benoitc  committed b0776ca

speed a little more restkit by making sure we close the response and
don't try to read it while it should be close. In the same time fix
BadStatusLine & ResponseNotReady error. (+70% increas on couchdbkit
tests).

  • Participants
  • Parent commits 802822e
  • Branches default

Comments (0)

Files changed (4)

File restkit/ext/eventlet_pool.py

View file
             if connection.sock is not None:
                 connection.close()
             return
-        
+
         try:
             response = connection.getresponse()
-            response.read()
+            response.close()
         except httplib.ResponseNotReady:
             pass
         except:
             connection.close()
+            connection = self.create()
             
         if connection.sock is None:
             connection = self.create()
+            
         Pool.put(self, connection)

File restkit/httpc.py

View file
                     continue
                 else:
                     raise
+            try:
+                response = connection.getresponse()
+            except httplib.HTTPException:
+                connection.close()
+                self._release_connection(uri, connection)
+                if i == 0:
+                    continue
+                else:
+                    raise
             break
                     
         # Return the HTTP Response from the server.
-        return connection
+        return response, connection
         
     def _request(self, uri, method, body, headers, nb_redirections=0):
         auths = [(auth.depth(uri), auth) for auth in self.authorizations if auth.inscope(uri.hostname, uri)]
         headers = _normalize_headers(headers)
         old_response = None
         
-        connection = self._make_request(uri, method, body, headers)
-        response = connection.getresponse()
+        response, connection = self._make_request(uri, method, body, headers)
         
         if auth and auth.response(response, body):
             auth.request(uri, method, headers, body)
-            connection = self._make_request(uri, method, body, headers)
-            response = connection.getresponse()
+            response, connection = self._make_request(uri, method, body, headers)
             
         if self.follow_redirect:
             if nb_redirections < self.MAX_REDIRECTIONS: 
             if data:
                 yield data
             else:
+                if not self.response.isclosed():
+                    self.response.close()
                 break
         if self.callback is not None:
             self.callback()

File restkit/pool.py

View file
                 connection.close()
             self.lock.release()
             return
-        
+           
         try:
             response = connection.getresponse()
-            response.read()
+            response.close()
         except httplib.ResponseNotReady:
             pass
         except:
             connection.close()
-            
+            connection = self.create()
             
         if connection.sock is None:
             connection = self.create()

File tests/httpc_test.py

View file
     def testGetBinary(self):
         import imghdr
         import tempfile
-        res = Resource('http://e-engura.org')
+        res = Resource('http://e-engura.com')
         result = res.get('/images/logo.gif')
         self.assert_(res.response.status == 200)
         fd, fname = tempfile.mkstemp(suffix='.gif')
     def testGetBinaryStreamed(self):
         import imghdr
         import tempfile
-        res = Resource('http://e-engura.org')
+        res = Resource('http://e-engura.com')
         result = res.get('/images/logo.gif', _stream=True)
         self.assert_(res.response.status == 200)
         fd, fname = tempfile.mkstemp(suffix='.gif')