Created
December 14, 2010 00:09
-
-
Save reedobrien/739823 to your computer and use it in GitHub Desktop.
quick fix for 500 errors when sending a HEAD request to deliverance-proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/deliverance/middleware.py b/deliverance/middleware.py | |
index 03c3b70..f44af34 100644 | |
--- a/deliverance/middleware.py | |
+++ b/deliverance/middleware.py | |
@@ -101,12 +101,18 @@ class DeliveranceMiddleware(object): | |
return self.clientside_response(req, rule_set, resource_fetcher, log)(environ, start_response) | |
else: | |
log.debug(self, 'Not doing clientside theming because jsEnabled cookie not set') | |
+ | |
+ headresp = None | |
+ if req.method == "HEAD": | |
+ headresp = req.get_response(self.app) | |
+ req.method = "GET" | |
resp = req.get_response(self.app) | |
+ | |
## FIXME: also XHTML? | |
if resp.content_type != 'text/html': | |
## FIXME: remove from known_html? | |
return resp(environ, start_response) | |
- | |
+ | |
# XXX: Not clear why such responses would have a content type, but | |
# they sometimes do (from Zope/Plone, at least) and that then breaks | |
# when trying to apply a theme. | |
@@ -128,8 +134,11 @@ class DeliveranceMiddleware(object): | |
resp.body = self._substitute_jsenable(resp.body) | |
resp = log.finish_request(req, resp) | |
+ if headresp: | |
+ headresp.headers = resp.headers | |
+ resp = headresp | |
return resp(environ, start_response) | |
- | |
+ | |
_title_re = re.compile(r'<title>(.*?)</title>', re.I|re.S) | |
def _get_title(self, body): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment