[CalendarServer-changes] [2195] CalendarServer/trunk/lib-patches/Twisted

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 4 19:49:48 PST 2008


Revision: 2195
          http://trac.macosforge.org/projects/calendarserver/changeset/2195
Author:   cdaboo at apple.com
Date:     2008-03-04 19:49:47 -0800 (Tue, 04 Mar 2008)

Log Message:
-----------
Fix for issue where SSL requests that return a response before reading the request body
sometimes hang the connection indefinitely and don't process any more requests.

Modified Paths:
--------------
    CalendarServer/trunk/lib-patches/Twisted/twisted.web2.http.patch

Added Paths:
-----------
    CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.test_pipeline.patch
    CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.tworequest_client.patch
    CalendarServer/trunk/lib-patches/Twisted/twisted.web2.test.test_http.patch

Added: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.test_pipeline.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.test_pipeline.patch	                        (rev 0)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.test_pipeline.patch	2008-03-05 03:49:47 UTC (rev 2195)
@@ -0,0 +1,74 @@
+Index: twisted/web2/dav/test/test_pipeline.py
+===================================================================
+--- twisted/web2/dav/test/test_pipeline.py	(revision 0)
++++ twisted/web2/dav/test/test_pipeline.py	(revision 0)
+@@ -0,0 +1,69 @@
++##
++# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
++#
++# Permission is hereby granted, free of charge, to any person obtaining a copy
++# of this software and associated documentation files (the "Software"), to deal
++# in the Software without restriction, including without limitation the rights
++# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++# copies of the Software, and to permit persons to whom the Software is
++# furnished to do so, subject to the following conditions:
++# 
++# The above copyright notice and this permission notice shall be included in all
++# copies or substantial portions of the Software.
++# 
++# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
++# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
++# SOFTWARE.
++#
++# DRI: Wilfredo Sanchez, wsanchez at apple.com
++##
++from twisted.internet import utils
++from twisted.web2.test import test_server
++from twisted.web2 import resource
++from twisted.web2 import http
++from twisted.web2.test import test_http
++import sys
++
++from twisted.internet.defer import waitForDeferred, deferredGenerator
++
++from twisted.python import util
++
++class Pipeline(test_server.BaseCase):
++    """
++    Pipelined request
++    """
++    class TestResource(resource.LeafResource):
++        def render(self, req):
++            return http.Response(stream="Host:%s, Path:%s"%(req.host, req.path))
++            
++    def setUp(self):
++        self.root = self.TestResource()
++
++    def chanrequest(self, root, uri, length, headers, method, version, prepath, content):
++        self.cr = super(Pipeline, self).chanrequest(root, uri, length, headers, method, version, prepath, content)
++        return self.cr
++
++    def test_root(self):
++        
++        def _testStreamRead(x):
++            self.assertTrue(self.cr.request.stream.length == 0)
++
++        return self.assertResponse(
++            (self.root, 'http://host/path', {"content-type":"text/plain",}, "PUT", None, '', "This is some text."),
++            (405, {}, None)).addCallback(_testStreamRead)
++
++class SSLPipeline(test_http.SSLServerTest):
++
++    @deferredGenerator
++    def testAdvancedWorkingness(self):
++        args = ('-u', util.sibpath(__file__, "tworequest_client.py"), "basic",
++                str(self.port), self.type)
++        d = waitForDeferred(utils.getProcessOutputAndValue(sys.executable, args=args))
++        yield d; out,err,code = d.getResult()
++
++        self.assertEquals(code, 0, "Error output:\n%s" % (err,))
++        self.assertEquals(out, "HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\nHTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\n")

Added: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.tworequest_client.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.tworequest_client.patch	                        (rev 0)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.test.tworequest_client.patch	2008-03-05 03:49:47 UTC (rev 2195)
@@ -0,0 +1,52 @@
+Index: twisted/web2/dav/test/tworequest_client.py
+===================================================================
+--- twisted/web2/dav/test/tworequest_client.py	(revision 0)
++++ twisted/web2/dav/test/tworequest_client.py	(revision 0)
+@@ -0,0 +1,47 @@
++import socket, sys
++
++test_type = sys.argv[1]
++port = int(sys.argv[2])
++socket_type = sys.argv[3]
++
++s = socket.socket(socket.AF_INET)
++s.connect(("127.0.0.1", port))
++s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 40000)
++
++if socket_type == 'ssl':
++    s2 = socket.ssl(s)
++    send=s2.write
++    recv=s2.read
++else:
++    send=s.send
++    recv=s.recv
++    
++print >> sys.stderr, ">> Making %s request to port %d" % (socket_type, port)
++
++send("PUT /forbidden HTTP/1.1\r\n")
++send("Host: localhost\r\n")
++
++print >> sys.stderr, ">> Sending lots of data"
++send("Content-Length: 100\r\n\r\n")
++send("X"*100)
++
++send("PUT /forbidden HTTP/1.1\r\n")
++send("Host: localhost\r\n")
++
++print >> sys.stderr, ">> Sending lots of data"
++send("Content-Length: 100\r\n\r\n")
++send("X"*100)
++
++#import time
++#time.sleep(5)
++print >> sys.stderr, ">> Getting data"
++data=''
++while len(data) < 299999:
++    try:
++        x=recv(10000)
++    except:
++        break
++    if x == '':
++        break
++    data+=x
++sys.stdout.write(data)

Modified: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.http.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.http.patch	2008-03-05 02:24:56 UTC (rev 2194)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.http.patch	2008-03-05 03:49:47 UTC (rev 2195)
@@ -2,6 +2,15 @@
 ===================================================================
 --- twisted/web2/http.py	(revision 19773)
 +++ twisted/web2/http.py	(working copy)
+@@ -26,7 +26,7 @@
+ from twisted.web2 import http_headers
+ from twisted.web2 import iweb
+ from twisted.web2 import stream
+-from twisted.web2.stream import IByteStream
++from twisted.web2.stream import IByteStream, readAndDiscard
+ 
+ defaultPortForScheme = {'http': 80, 'https':443, 'ftp':21}
+ 
 @@ -66,9 +66,9 @@
              object.
          @type codeOrResponse: C{int} or L{http.Response}
@@ -15,3 +24,27 @@
  
      def __repr__(self):
          return "<%s %s>" % (self.__class__.__name__, self.response)
+@@ -408,9 +408,22 @@
+     def _sendContinue(self):
+         self.chanRequest.writeIntermediateResponse(responsecode.CONTINUE)
+ 
+-    def _finished(self, x):
++    def _reallyFinished(self, x):
+         """We are finished writing data."""
+         self.chanRequest.finish()
++        
++    def _finished(self, x):
++        """
++        We are finished writing data.
++        But we need to check that we have also finished reading all data as we
++        might have sent a, for example, 401 response before we read any data.
++        To make sure that the stream/producer sequencing works properly we need
++        to discard the remaining data in the request.  
++        """
++        if self.stream.length != 0:
++            return readAndDiscard(self.stream).addCallback(self._reallyFinished).addErrback(self._error)
++        else:
++            self._reallyFinished(x)
+ 
+     def _error(self, reason):
+         if reason.check(error.ConnectionLost):

Added: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.test.test_http.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.test.test_http.patch	                        (rev 0)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.test.test_http.patch	2008-03-05 03:49:47 UTC (rev 2195)
@@ -0,0 +1,13 @@
+Index: twisted/web2/test/test_http.py
+===================================================================
+--- twisted/web2/test/test_http.py	(revision 19773)
++++ twisted/web2/test/test_http.py	(working copy)
+@@ -1017,6 +1017,8 @@
+         response = TestResponse()
+         if self.uri == "/error":
+             response.code=402
++        elif self.uri == "/forbidden":
++            response.code=403
+         else:
+             response.code=404
+             response.write("URI %s unrecognized." % self.uri)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080304/f9732eef/attachment.html 


More information about the calendarserver-changes mailing list