[Twisted-Python] fixes for web.proxy

Paul Boehm typo at soniq.net
Mon Dec 2 22:08:01 EST 2002


hi,
twisted.web.proxy didn't work for me.

i've included two fixes.. a) makes Proxy a factory which
current twisted can use.

and b) is a neccesary change to deal with pages sending just \n
i dunno how to implemented this best, but proxy or HTTPClient
are unusable if they depend on \r\n being sent.

maybe lineReceiver needs a new mode to accept \r\n AND \n
as delimiters, but removing both?

here are my diffs:

diff -u -r1.9 proxy.py
--- web/proxy.py    15 Nov 2002 20:47:36 -0000  1.9
+++ web/proxy.py    3 Dec 2002 03:05:18 -0000
@@ -27,6 +27,7 @@


 class ProxyClient(http.HTTPClient):
+    delimiter = '\n'

     def __init__(self, command, rest, version, headers, data, father):
         self.father = father
@@ -106,9 +107,15 @@
                                s, self)
         reactor.connectTCP(host, port, clientFactory)

-class Proxy(http.HTTPChannel):
-
-    requestFactory = ProxyRequest
+class Proxy(http.HTTPFactory):
+    def buildProtocol(self, addr):
+        """Generate a channel attached to this site.
+        """
+        channel = http.HTTPChannel()
+        channel.requestFactory = ProxyRequest
+        channel.site = self
+        channel.factory = self
+        return channel


 class ReverseProxyRequest(http.Request):
Index: protocols/http.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/http.py,v
retrieving revision 1.63
diff -u -r1.63 http.py
--- protocols/http.py   15 Nov 2002 20:57:58 -0000  1.63
+++ protocols/http.py   3 Dec 2002 03:05:20 -0000
@@ -268,6 +268,7 @@
     length = None
     firstLine = 1
     __buffer = ''
+    delimiter = '\n'

     def sendCommand(self, command, path):
         self.transport.write('%s %s HTTP/1.0\r\n' % (command, path))
@@ -279,6 +280,8 @@
         self.transport.write('\r\n')

     def lineReceived(self, line):
+        if line[-1] == '\r':
+            line = line[0:-1]
         if self.firstLine:
             self.firstLine = 0
             try:





More information about the Twisted-Python mailing list