[Zope-CVS] CVS: Packages/tcpwatch - tcpwatch:1.11
Shane Hathaway
shane@cvs.zope.org
Fri, 22 Feb 2002 18:37:35 -0500
Update of /cvs-repository/Packages/tcpwatch
In directory cvs.zope.org:/tmp/cvs-serv21854
Modified Files:
tcpwatch
Log Message:
Made HTTPProxyToServerConnection derive from ForwardingEndpoint so I can
later check off two more TODOs
=== Packages/tcpwatch/tcpwatch 1.10 => 1.11 ===
-class HTTPProxyResponseBuffer:
+class HTTPProxyToServerConnection (ForwardingEndpoint):
"""Ensures that responses to a persistent HTTP connection occur
in the correct order."""
- # TODO: inherit from ForwardingEndpoint so it's possible to
- # close the server connection. Rename to HTTPProxyToServerConnection.
finished = 0
- def __init__(self, proxy_conn, watching_streams=()):
+ def __init__(self, proxy_conn, dests=()):
+ ForwardingEndpoint.__init__(self)
self.response_parser = HTTPStreamParser(0)
self.proxy_conn = proxy_conn
- self.watching_streams = watching_streams
- self.held = [] # Data held in the buffer
+ self.set_dests(dests)
+
+ # Data for the client held until previous responses are sent
+ self.held = []
def _isMyTurn(self):
"""Returns a true value if it's time for this response
to respond to the client."""
- bufs = self.proxy_conn._response_buffers
- if bufs:
- return (bufs[0] is self)
+ order = self.proxy_conn._response_order
+ if order:
+ return (order[0] is self)
return 1
- def write(self, data):
+ def received(self, data):
"""Receives data from the HTTP server to be sent back to the client."""
while 1:
parser = self.response_parser
@@ -971,8 +972,7 @@
consumed = parser.received(data)
fragment = data[:consumed]
data = data[consumed:]
- for s in self.watching_streams:
- s.write(fragment)
+ ForwardingEndpoint.received(self, fragment)
self.held.append(fragment)
self.flush()
@@ -984,33 +984,26 @@
del self.held[:]
self.proxy_conn.write(data)
if self.finished:
- bufs = self.proxy_conn._response_buffers
- if bufs and bufs[0] is self:
- del bufs[0]
- if bufs:
- bufs[0].flush() # kick!
+ order = self.proxy_conn._response_order
+ if order and order[0] is self:
+ del order[0]
+ if order:
+ order[0].flush() # kick!
def close(self):
"""The HTTP server closed the connection.
"""
- for s in self.watching_streams:
- s.close()
+ ForwardingEndpoint.close(self)
if not self.finished:
# TODO: cancel the proxy connection.
pass
self.finished = 1
self.flush()
- def error(self, t, v):
- for s in self.watching_streams:
- if hasattr(s, 'error'):
- s.error(t, v)
-
-class HTTPProxyConnection (ForwardingEndpoint):
+class HTTPProxyToClientConnection (ForwardingEndpoint):
"""A connection from a client to the proxy server"""
- # TODO: rename to HTTPProxyToClientConnection.
_req_parser = None
_transaction = 0
@@ -1021,7 +1014,7 @@
self._obs_factory = factory
self._counter = counter
self._client_addr = addr
- self._response_buffers = []
+ self._response_order = []
self._newRequest()
def _newRequest(self):
@@ -1095,23 +1088,22 @@
obs = self._obs
if obs is not None:
eo = EndpointObserver(obs, 0)
- buf = HTTPProxyResponseBuffer(self, (eo,))
+ ptos = HTTPProxyToServerConnection(self, (eo,))
else:
- buf = HTTPProxyResponseBuffer(self)
- self._response_buffers.append(buf)
+ ptos = HTTPProxyToServerConnection(self)
+
+ self._response_order.append(ptos)
- ep = ForwardingEndpoint() # connects server to buf (to self)
- ep.write('%s %s %s\r\n' % (command, path, protocol))
+ ptos.write('%s %s %s\r\n' % (command, path, protocol))
# Duplicate the headers sent by the client.
if request.header:
- ep.write(request.header)
+ ptos.write(request.header)
else:
- ep.write('\r\n')
+ ptos.write('\r\n')
if request.body_data:
- ep.write(''.join(request.body_data))
- ep.set_dests((buf,))
- ep.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- ep.connect((host, port))
+ ptos.write(''.join(request.body_data))
+ ptos.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ ptos.connect((host, port))
def close(self):
ForwardingEndpoint.close(self)
@@ -1139,7 +1131,7 @@
conn.setblocking(0)
counter = self._counter + 1
self._counter = counter
- HTTPProxyConnection(conn, self._obs_factory, counter, addr)
+ HTTPProxyToClientConnection(conn, self._obs_factory, counter, addr)
def handle_error(self):
# Don't stop the server.