[CalendarServer-changes] [3826] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 11 15:31:38 PDT 2009
Revision: 3826
http://trac.macosforge.org/projects/calendarserver/changeset/3826
Author: wsanchez at apple.com
Date: 2009-03-11 15:31:38 -0700 (Wed, 11 Mar 2009)
Log Message:
-----------
Move HTTP503LoggingFactory to twext.web2.channel.http
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/setup.py
Added Paths:
-----------
CalendarServer/trunk/twext/web2/channel/
CalendarServer/trunk/twext/web2/channel/__init__.py
CalendarServer/trunk/twext/web2/channel/http.py
Removed Paths:
-------------
CalendarServer/trunk/twistedcaldav/httpfactory.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2009-03-11 22:31:17 UTC (rev 3825)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2009-03-11 22:31:38 UTC (rev 3826)
@@ -52,6 +52,7 @@
from twisted.web2.http import Request, RedirectResponse
from twext.internet.ssl import ChainingOpenSSLContextFactory
+from twext.web2.channel.http import HTTP503LoggingFactory
from twistedcaldav.log import Logger, LoggingMixIn
from twistedcaldav.log import logLevelForNamespace, setLogLevelForNamespace
@@ -68,7 +69,6 @@
from twistedcaldav.directory.sudo import SudoDirectoryService
from twistedcaldav.directory.util import NotFilePath
from twistedcaldav.directory.wiki import WikiDirectoryService
-from twistedcaldav.httpfactory import HTTP503LoggingFactory
from twistedcaldav.static import CalendarHomeProvisioningFile
from twistedcaldav.static import IScheduleInboxFile
from twistedcaldav.static import TimezoneServiceFile
@@ -676,8 +676,8 @@
channel = HTTP503LoggingFactory(
site,
maxRequests = config.MaxRequests,
+ retryAfter = config.HTTPRetryAfter,
betweenRequestsTimeOut = config.IdleConnectionTimeOut,
- retryAfter = config.HTTPRetryAfter,
)
def updateChannel(config, items):
Modified: CalendarServer/trunk/setup.py
===================================================================
--- CalendarServer/trunk/setup.py 2009-03-11 22:31:17 UTC (rev 3825)
+++ CalendarServer/trunk/setup.py 2009-03-11 22:31:38 UTC (rev 3826)
@@ -138,6 +138,7 @@
"twext.internet",
"twext.python",
"twext.web2",
+ "twext.web2.channel",
"twistedcaldav",
"twistedcaldav.admin",
"twistedcaldav.directory",
Copied: CalendarServer/trunk/twext/web2/channel/__init__.py (from rev 3818, CalendarServer/trunk/twext/web2/__init__.py)
===================================================================
--- CalendarServer/trunk/twext/web2/channel/__init__.py (rev 0)
+++ CalendarServer/trunk/twext/web2/channel/__init__.py 2009-03-11 22:31:38 UTC (rev 3826)
@@ -0,0 +1,19 @@
+##
+# Copyright (c) 2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Extentions to twisted.web2.channel
+"""
Copied: CalendarServer/trunk/twext/web2/channel/http.py (from rev 3818, CalendarServer/trunk/twistedcaldav/httpfactory.py)
===================================================================
--- CalendarServer/trunk/twext/web2/channel/http.py (rev 0)
+++ CalendarServer/trunk/twext/web2/channel/http.py 2009-03-11 22:31:38 UTC (rev 3826)
@@ -0,0 +1,69 @@
+##
+# Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twisted.internet import protocol
+from twisted.python import log
+from twisted.web2.channel.http import HTTPFactory
+
+__all__ = [
+ "HTTP503LoggingFactory",
+]
+
+class OverloadedLoggingServerProtocol (protocol.Protocol):
+ def __init__(self, retryAfter, outstandingRequests):
+ self.retryAfter = retryAfter
+ self.outstandingRequests = outstandingRequests
+
+ def connectionMade(self):
+ log.msg(overloaded=self)
+
+ self.transport.write(
+ "HTTP/1.0 503 Service Unavailable\r\n"
+ "Content-Type: text/html\r\n"
+ )
+
+ if self.retryAfter:
+ self.transport.write(
+ "Retry-After: %s\r\n" % (self.retryAfter,)
+ )
+
+ self.transport.write(
+ "Connection: close\r\n\r\n"
+ "<html><head><title>Service Unavailable</title></head>"
+ "<body><h1>Service Unavailable</h1>"
+ "The server is currently overloaded, "
+ "please try again later.</body></html>"
+ )
+ self.transport.loseConnection()
+
+class HTTP503LoggingFactory (HTTPFactory):
+ """
+ Factory for HTTP server which emits a 503 response when overloaded.
+ """
+ def __init__(self, requestFactory, maxRequests=600, retryAfter=0, **kwargs):
+ self.retryAfter = retryAfter
+ HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
+
+ def buildProtocol(self, addr):
+ if self.outstandingRequests >= self.maxRequests:
+ return OverloadedLoggingServerProtocol(self.retryAfter, self.outstandingRequests)
+
+ p = protocol.ServerFactory.buildProtocol(self, addr)
+
+ for arg,value in self.protocolArgs.iteritems():
+ setattr(p, arg, value)
+
+ return p
Deleted: CalendarServer/trunk/twistedcaldav/httpfactory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/httpfactory.py 2009-03-11 22:31:17 UTC (rev 3825)
+++ CalendarServer/trunk/twistedcaldav/httpfactory.py 2009-03-11 22:31:38 UTC (rev 3826)
@@ -1,70 +0,0 @@
-##
-# Copyright (c) 2008-2009 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-from twisted.internet import protocol
-from twisted.python import log
-from twisted.web2.channel.http import HTTPFactory
-
-__all__ = [
- "HTTP503LoggingFactory",
-]
-
-class OverloadedLoggingServerProtocol(protocol.Protocol):
- def __init__(self, retryAfter, outstandingRequests):
- self.retryAfter = retryAfter
- self.outstandingRequests = outstandingRequests
-
- def connectionMade(self):
- log.msg(overloaded=self)
-
- self.transport.write(
- "HTTP/1.0 503 Service Unavailable\r\n"
- "Content-Type: text/html\r\n"
- )
-
- if self.retryAfter:
- self.transport.write(
- "Retry-After: %s\r\n" % (self.retryAfter,)
- )
-
- self.transport.write(
- "Connection: close\r\n\r\n"
- "<html><head><title>Service Unavailable</title></head>"
- "<body><h1>Service Unavailable</h1>"
- "The server is currently overloaded, "
- "please try again later.</body></html>"
- )
- self.transport.loseConnection()
-
-class HTTP503LoggingFactory(HTTPFactory):
- """
- Factory for HTTP server which emits a 503 response when overloaded.
- """
-
- def __init__(self, requestFactory, maxRequests=600, retryAfter=0, **kwargs):
- self.retryAfter = retryAfter
- HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
-
- def buildProtocol(self, addr):
- if self.outstandingRequests >= self.maxRequests:
- return OverloadedLoggingServerProtocol(self.retryAfter, self.outstandingRequests)
-
- p = protocol.ServerFactory.buildProtocol(self, addr)
-
- for arg,value in self.protocolArgs.iteritems():
- setattr(p, arg, value)
-
- return p
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090311/09202322/attachment.html>
More information about the calendarserver-changes
mailing list