[CalendarServer-changes] [15596] CalendarServer/trunk/twistedcaldav/client/reverseproxy.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 17 18:08:08 PDT 2016
Revision: 15596
http://trac.calendarserver.org//changeset/15596
Author: cdaboo at apple.com
Date: 2016-05-17 18:08:08 -0700 (Tue, 17 May 2016)
Log Message:
-----------
Better errors, logging for reverse proxy cross-pod failures.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/client/reverseproxy.py
Modified: CalendarServer/trunk/twistedcaldav/client/reverseproxy.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/client/reverseproxy.py 2016-05-16 19:44:36 UTC (rev 15595)
+++ CalendarServer/trunk/twistedcaldav/client/reverseproxy.py 2016-05-18 01:08:08 UTC (rev 15596)
@@ -30,6 +30,9 @@
from twistedcaldav.client.pool import getHTTPClientPool
from twistedcaldav.config import config
+from twisted.internet.defer import returnValue, inlineCallbacks
+
+
class ReverseProxyResource(LeafResource):
"""
A L{LeafResource} which always performs a reverse proxy operation.
@@ -41,7 +44,7 @@
def __init__(self, poolID, *args, **kwargs):
"""
- @param poolID: idenitifier of the pool to use
+ @param poolID: identifier of the pool to use
@type poolID: C{str}
"""
@@ -59,6 +62,7 @@
return False
+ @inlineCallbacks
def renderHTTP(self, request):
"""
Do the reverse proxy request and return the response.
@@ -69,7 +73,7 @@
@return: Deferred L{Response}
"""
- self.log.info("{method} {uri} {proto}", method=request.method, uri=request.uri, proto="HTTP/%s.%s" % request.clientproto)
+ self.log.info("{method} {poolID}:{uri} {proto}", method=request.method, poolID=self.poolID, uri=request.uri, proto="HTTP/{}.{}".format(*request.clientproto))
# Check for multi-hop
if not self.allowMultiHop:
@@ -77,6 +81,7 @@
if x_server:
for item in x_server:
if item.lower() == config.ServerHostName.lower():
+ self.log.error("ReverseProxy loop detected: x-forwarded-server:{xfs}", xfs=str(x_server))
raise HTTPError(StatusResponse(responsecode.BAD_GATEWAY, "Too many x-forwarded-server hops"))
clientPool = getHTTPClientPool(self.poolID)
@@ -90,4 +95,10 @@
proxyRequest.headers.addRawHeader("x-forwarded-for", request.remoteAddr.host)
proxyRequest.headers.addRawHeader("x-forwarded-server", config.ServerHostName)
- return clientPool.submitRequest(proxyRequest)
+ try:
+ response = yield clientPool.submitRequest(proxyRequest)
+ except Exception as e:
+ self.log.error("ReverseProxy failed: {exc}", exc=str(e))
+ raise HTTPError(StatusResponse(responsecode.BAD_GATEWAY, "Cannot connect via poolID={poolID}".format(poolID=self.poolID)))
+
+ returnValue(response)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160517/e6492cb2/attachment.html>
More information about the calendarserver-changes
mailing list