##// END OF EJS Templates
keepalive: track number of bytes received from an HTTP response...
Gregory Szorc -
r40069:5e5b0608 default
parent child Browse files
Show More
@@ -392,6 +392,7 b' class HTTPResponse(httplib.HTTPResponse)'
392 method=method, **extrakw)
392 method=method, **extrakw)
393 self.fileno = sock.fileno
393 self.fileno = sock.fileno
394 self.code = None
394 self.code = None
395 self.receivedbytescount = 0
395 self._rbuf = ''
396 self._rbuf = ''
396 self._rbufsize = 8096
397 self._rbufsize = 8096
397 self._handler = None # inserted by the handler later
398 self._handler = None # inserted by the handler later
@@ -436,7 +437,16 b' class HTTPResponse(httplib.HTTPResponse)'
436 # if it's not empty.
437 # if it's not empty.
437 s = self._rbuf
438 s = self._rbuf
438 self._rbuf = ''
439 self._rbuf = ''
439 s += self._raw_read(amt)
440 data = self._raw_read(amt)
441
442 self.receivedbytescount += len(data)
443 self._connection.receivedbytescount += len(data)
444 try:
445 self._handler.parent.receivedbytescount += len(data)
446 except AttributeError:
447 pass
448
449 s += data
440 return s
450 return s
441
451
442 # stolen from Python SVN #68532 to fix issue1088
452 # stolen from Python SVN #68532 to fix issue1088
@@ -512,6 +522,13 b' class HTTPResponse(httplib.HTTPResponse)'
512 if not new:
522 if not new:
513 break
523 break
514
524
525 self.receivedbytescount += len(new)
526 self._connection.receivedbytescount += len(new)
527 try:
528 self._handler.parent.receivedbytescount += len(new)
529 except AttributeError:
530 pass
531
515 chunks.append(new)
532 chunks.append(new)
516 i = new.find('\n')
533 i = new.find('\n')
517 if i >= 0:
534 if i >= 0:
@@ -557,6 +574,14 b' class HTTPResponse(httplib.HTTPResponse)'
557 return total
574 return total
558 mv = memoryview(dest)
575 mv = memoryview(dest)
559 got = self._raw_readinto(mv[have:total])
576 got = self._raw_readinto(mv[have:total])
577
578 self.receivedbytescount += got
579 self._connection.receivedbytescount += got
580 try:
581 self._handler.receivedbytescount += got
582 except AttributeError:
583 pass
584
560 dest[0:have] = self._rbuf
585 dest[0:have] = self._rbuf
561 got += len(self._rbuf)
586 got += len(self._rbuf)
562 self._rbuf = ''
587 self._rbuf = ''
@@ -643,6 +668,7 b' class HTTPConnection(httplib.HTTPConnect'
643 def __init__(self, *args, **kwargs):
668 def __init__(self, *args, **kwargs):
644 httplib.HTTPConnection.__init__(self, *args, **kwargs)
669 httplib.HTTPConnection.__init__(self, *args, **kwargs)
645 self.sentbytescount = 0
670 self.sentbytescount = 0
671 self.receivedbytescount = 0
646
672
647 #########################################################################
673 #########################################################################
648 ##### TEST FUNCTIONS
674 ##### TEST FUNCTIONS
General Comments 0
You need to be logged in to leave comments. Login now