Show More
@@ -174,6 +174,8 b' class ConnectionManager(object):' | |||
|
174 | 174 | class KeepAliveHandler(object): |
|
175 | 175 | def __init__(self): |
|
176 | 176 | self._cm = ConnectionManager() |
|
177 | self.requestscount = 0 | |
|
178 | self.sentbytescount = 0 | |
|
177 | 179 | |
|
178 | 180 | #### Connection Management |
|
179 | 181 | def open_connections(self): |
@@ -312,6 +314,8 b' class KeepAliveHandler(object):' | |||
|
312 | 314 | return r |
|
313 | 315 | |
|
314 | 316 | def _start_transaction(self, h, req): |
|
317 | oldbytescount = h.sentbytescount | |
|
318 | ||
|
315 | 319 | # What follows mostly reimplements HTTPConnection.request() |
|
316 | 320 | # except it adds self.parent.addheaders in the mix and sends headers |
|
317 | 321 | # in a deterministic order (to make testing easier). |
@@ -346,6 +350,16 b' class KeepAliveHandler(object):' | |||
|
346 | 350 | if urllibcompat.hasdata(req): |
|
347 | 351 | h.send(data) |
|
348 | 352 | |
|
353 | # This will fail to record events in case of I/O failure. That's OK. | |
|
354 | self.requestscount += 1 | |
|
355 | self.sentbytescount += h.sentbytescount - oldbytescount | |
|
356 | ||
|
357 | try: | |
|
358 | self.parent.requestscount += 1 | |
|
359 | self.parent.sentbytescount += h.sentbytescount - oldbytescount | |
|
360 | except AttributeError: | |
|
361 | pass | |
|
362 | ||
|
349 | 363 | class HTTPHandler(KeepAliveHandler, urlreq.httphandler): |
|
350 | 364 | pass |
|
351 | 365 | |
@@ -585,9 +599,11 b' def safesend(self, str):' | |||
|
585 | 599 | data = read(blocksize) |
|
586 | 600 | while data: |
|
587 | 601 | self.sock.sendall(data) |
|
602 | self.sentbytescount += len(data) | |
|
588 | 603 | data = read(blocksize) |
|
589 | 604 | else: |
|
590 | 605 | self.sock.sendall(str) |
|
606 | self.sentbytescount += len(str) | |
|
591 | 607 | except socket.error as v: |
|
592 | 608 | reraise = True |
|
593 | 609 | if v[0] == errno.EPIPE: # Broken pipe |
@@ -624,6 +640,9 b' class HTTPConnection(httplib.HTTPConnect' | |||
|
624 | 640 | send = safesend |
|
625 | 641 | getresponse = wrapgetresponse(httplib.HTTPConnection) |
|
626 | 642 | |
|
643 | def __init__(self, *args, **kwargs): | |
|
644 | httplib.HTTPConnection.__init__(self, *args, **kwargs) | |
|
645 | self.sentbytescount = 0 | |
|
627 | 646 | |
|
628 | 647 | ######################################################################### |
|
629 | 648 | ##### TEST FUNCTIONS |
General Comments 0
You need to be logged in to leave comments.
Login now