@@ -160,7 +160,12 @@ def _release_conn(self):
160
160
161
161
def close (self ):
162
162
while not self .resp .isclosed ():
163
- self .resp .read (CHUNK_SIZE )
163
+ chunk = self .resp .read (CHUNK_SIZE )
164
+ #alexandre-couchdb-python-app-engine changes
165
+ # on App Engine self.resp.isclosed() is always False and leads to an infinite loop
166
+ if len (chunk ) == 0 :
167
+ self .resp .close ()
168
+ ###################################
164
169
if self .conn :
165
170
self ._release_conn ()
166
171
@@ -271,6 +276,17 @@ def request(self, method, url, body=None, headers=None, credentials=None,
271
276
headers ['Authorization' ] = authorization
272
277
273
278
path_query = util .urlunsplit (('' , '' ) + util .urlsplit (url )[2 :4 ] + ('' ,))
279
+
280
+ #alexandre-couchdb-python-app-engine change
281
+ #Use the same connection object with multiple POST requests on app engine
282
+ #concatenates successive requests bodies
283
+ # e.g
284
+ # Req1: body1
285
+ # Req2: body1 body2
286
+ # Req3: body1 body2 body3
287
+ # ...
288
+ if method == "POST" or method == "PUT" :
289
+ self .connection_pool .remove (url )
274
290
conn = self .connection_pool .get (url )
275
291
276
292
def _try_request_with_retries (retries ):
@@ -493,6 +509,14 @@ def release(self, url, conn):
493
509
finally :
494
510
self .lock .release ()
495
511
512
+ #alexandre-couchdb-python-app-engine Change
513
+ def remove (self , url ):
514
+ scheme , host = util .urlsplit (url , 'http' , False )[:2 ]
515
+ connList = self .conns [(scheme ,host )]
516
+ for conn in connList :
517
+ conn .close () #No Op on Google App Engine
518
+ self .conns .pop ((scheme ,host ),0 )
519
+
496
520
def __del__ (self ):
497
521
for key , conns in list (self .conns .items ()):
498
522
for conn in conns :
0 commit comments