[Zope-CVS] CVS: Packages/tcpwatch - tcpwatch:1.6
Shane Hathaway
shane@cvs.zope.org
Thu, 21 Feb 2002 00:58:29 -0500
Update of /cvs-repository/Packages/tcpwatch
In directory cvs.zope.org:/tmp/cvs-serv4444
Modified Files:
tcpwatch
Log Message:
Proxy feature now tested with Mozilla on several sites.
=== Packages/tcpwatch/tcpwatch 1.5 => 1.6 ===
finished = 0
- def __init__(self, proxy_conn, observer_stream=None):
+ def __init__(self, proxy_conn, observers=()):
self.response_parser = HTTPStreamParser(0)
self.proxy_conn = proxy_conn
- self.observer_stream = observer_stream
+ self.observers = observers
self.held = []
def _isMyTurn(self):
@@ -921,22 +921,23 @@
def write(self, data):
# Received data from the server.
- parser = self.response_parser
- if not parser.completed:
- parser.received(data)
- if parser.completed:
- self.finished = 1
+ while data:
+ parser = self.response_parser
+ if parser.completed:
+ self.finished = 1
+ self.flush()
+ return
+ consumed = parser.received(data)
+ fragment = data[:consumed]
+ data = data[consumed:]
+ for o in self.observers:
+ o.write(fragment)
+ if not self._isMyTurn():
+ # Wait for earlier responses to finish.
+ self.held.append(fragment)
+ return
self.flush()
- return
- observer_stream = self.observer_stream
- if observer_stream is not None:
- observer_stream.write(data)
- if not self._isMyTurn():
- # Wait for earlier responses to finish.
- self.held.append(data)
- return
- self.flush()
- self.proxy_conn.write(data)
+ self.proxy_conn.write(fragment)
def flush(self):
if self.held and self._isMyTurn():
@@ -951,16 +952,14 @@
bufs[0].flush() # kick.
def close(self):
- observer_stream = self.observer_stream
- if observer_stream is not None:
- observer_stream.close()
+ for o in self.observers:
+ o.close()
self.finished = 1
self.flush()
def error(self, t, v):
- observer_stream = self.observer_stream
- if observer_stream is not None:
- observer_stream.error(t, v)
+ for o in self.observers:
+ o.error(t, v)
@@ -1044,7 +1043,7 @@
obs = self._obs
if obs is not None:
eo = EndpointObserver(obs, 0)
- buf = HTTPProxyResponseBuffer(self, eo)
+ buf = HTTPProxyResponseBuffer(self, (eo,))
else:
buf = HTTPProxyResponseBuffer(self)
self._response_buffers.append(buf)
@@ -1055,8 +1054,6 @@
ep.write('\r\n')
ep.set_dests((buf,))
ep.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- print 'connecting to', repr((host, port))
- print repr(request.header_plus)
ep.connect((host, port))