[CalendarServer-changes] [6108] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 18 10:58:54 PDT 2010


Revision: 6108
          http://trac.macosforge.org/projects/calendarserver/changeset/6108
Author:   sagen at apple.com
Date:     2010-08-18 10:58:53 -0700 (Wed, 18 Aug 2010)
Log Message:
-----------
Enable RedirectHTTPToHTTPS for MetaFD

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/twext/web2/channel/http.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2010-08-18 17:53:16 UTC (rev 6107)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2010-08-18 17:58:53 UTC (rev 6108)
@@ -521,30 +521,24 @@
 
         service = CalDAVService(logObserver)
 
-        site = Site(rootResource)
+        underlyingSite = Site(rootResource)
+        requestFactory = underlyingSite
 
+        if config.RedirectHTTPToHTTPS:
+            def requestFactory(*args, **kw):
+                return SSLRedirectRequest(site=underlyingSite, *args, **kw)
+
         httpFactory = LimitingHTTPFactory(
-            site,
+            requestFactory,
             maxRequests=config.MaxRequests,
             maxAccepts=config.MaxAccepts,
             betweenRequestsTimeOut=config.IdleConnectionTimeOut,
             vary=True,
         )
-        if config.RedirectHTTPToHTTPS:
-            redirectFactory = LimitingHTTPFactory(
-                SSLRedirectRequest,
-                maxRequests=config.MaxRequests,
-                maxAccepts=config.MaxAccepts,
-                betweenRequestsTimeOut=config.IdleConnectionTimeOut,
-                vary=True,
-            )
 
         def updateFactory(configDict):
             httpFactory.maxRequests = configDict.MaxRequests
             httpFactory.maxAccepts = configDict.MaxAccepts
-            if config.RedirectHTTPToHTTPS:
-                redirectFactory.maxRequests = configDict.MaxRequests
-                redirectFactory.maxAccepts = configDict.MaxAccepts
 
         config.addPostUpdateHooks((updateFactory,))
 
@@ -571,12 +565,9 @@
 
                 if config.RedirectHTTPToHTTPS:
                     self.log_info("Redirecting to HTTPS port %s" % (config.SSLPort,))
-                    useFactory = redirectFactory
-                else:
-                    useFactory = httpFactory
 
                 MaxAcceptTCPServer(
-                    fd, useFactory,
+                    fd, httpFactory,
                     backlog=config.ListenBacklog,
                     inherit=True
                 ).setServiceParent(service)
@@ -597,7 +588,7 @@
                 contextFactory = None
 
             ReportingHTTPService(
-                site, fd, contextFactory
+                requestFactory, fd, contextFactory
             ).setServiceParent(service)
 
         else: # Not inheriting, therefore we open our own:
@@ -650,16 +641,14 @@
                         self.log_info("Redirecting HTTP port %s to HTTPS port %s"
                             % (port, config.SSLPort)
                         )
-                        useFactory = redirectFactory
                     else:
                         self.log_info(
                             "Adding server at %s:%s"
                             % (bindAddress, port)
                         )
-                        useFactory = httpFactory
 
                     MaxAcceptTCPServer(
-                        int(port), useFactory,
+                        int(port), httpFactory,
                         interface=bindAddress,
                         backlog=config.ListenBacklog,
                         inherit=False

Modified: CalendarServer/trunk/twext/web2/channel/http.py
===================================================================
--- CalendarServer/trunk/twext/web2/channel/http.py	2010-08-18 17:53:16 UTC (rev 6107)
+++ CalendarServer/trunk/twext/web2/channel/http.py	2010-08-18 17:58:53 UTC (rev 6108)
@@ -38,7 +38,8 @@
 from twext.web2 import responsecode
 from twext.web2 import http_headers
 from twext.web2 import http
-from twext.web2.http import Request, RedirectResponse
+from twext.web2.http import RedirectResponse
+from twext.web2.server import Request
 
 from twistedcaldav.config import config
 from twistedcaldav import accounting
@@ -77,17 +78,21 @@
     """ For redirecting HTTP to HTTPS port """
 
     def process(self):
-        if config.SSLPort == 443:
-            location = (
-                "https://%s%s"
-                % (config.ServerHostName, self.uri)
-            )
+        ignored, secure = self.chanRequest.getHostInfo()
+        if not secure:
+            if config.SSLPort == 443:
+                location = (
+                    "https://%s%s"
+                    % (config.ServerHostName, self.uri)
+                )
+            else:
+                location = (
+                    "https://%s:%d%s"
+                    % (config.ServerHostName, config.SSLPort, self.uri)
+                )
+            self.writeResponse(RedirectResponse(location))
         else:
-            location = (
-                "https://%s:%d%s"
-                % (config.ServerHostName, config.SSLPort, self.uri)
-            )
-        self.writeResponse(RedirectResponse(location))
+            return super(SSLRedirectRequest, self).process()
 
 # >%
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100818/47310c99/attachment-0001.html>


More information about the calendarserver-changes mailing list