[Twisted-Python] fixes for web.proxy

Paul Boehm typo at soniq.net
Tue Dec 3 09:03:04 EST 2002


this is a more generic fix, that adds special handling for services
where crlf and lf are interchangeable.

comments, please!

also i'd like to get feedback on proxy maintainership.
if noone disagrees i'll make a plugin for proxy,
and try to polish it up, so that it becomes actually useable.

  paul

Index: protocols/basic.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/basic.py,v
retrieving revision 1.27
diff -u -r1.27 basic.py
--- protocols/basic.py	15 Nov 2002 14:56:18 -0000	1.27
+++ protocols/basic.py	3 Dec 2002 13:57:30 -0000
@@ -147,6 +147,7 @@
     line_mode = 1
     __buffer = ''
     delimiter = '\r\n'
+    crlfhack = 0
     MAX_LENGTH = 16384
 
     def dataReceived(self, data):
@@ -157,7 +158,16 @@
         self.__buffer = self.__buffer+data
         while self.line_mode:
             try:
-                line, self.__buffer = self.__buffer.split(self.delimiter, 1)
+                if self.crlfhack:
+                    delimiter = '\n'
+                else:
+                    delimiter = self.delimiter
+
+                line, self.__buffer = self.__buffer.split(delimiter, 1)
+
+                if self.crlfhack:
+                    line = line.replace('\r', '')
+
             except ValueError:
                 if len(self.__buffer) > self.MAX_LENGTH:
                     self.transport.loseConnection()
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 13:57:32 -0000
@@ -268,6 +268,8 @@
     length = None
     firstLine = 1
     __buffer = ''
+    delimiter = '\r\n'
+    crlfhack = 1
 
     def sendCommand(self, command, path):
         self.transport.write('%s %s HTTP/1.0\r\n' % (command, path))
Index: web/proxy.py
===================================================================
RCS file: /cvs/Twisted/twisted/web/proxy.py,v
retrieving revision 1.9
diff -u -r1.9 proxy.py
--- web/proxy.py	15 Nov 2002 20:47:36 -0000	1.9
+++ web/proxy.py	3 Dec 2002 13:57:32 -0000
@@ -106,9 +106,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):




More information about the Twisted-Python mailing list