Author: justi9
Date: 2008-04-14 11:47:46 -0400 (Mon, 14 Apr 2008)
New Revision: 1906
Modified:
mgmt/cumin/python/wooly/server.py
Log:
A couple changes that make the web server faster.
Restore if-modified-since support under the new web server.
Set the content length on response and thus avoid the slightly slower
chunked-encoding path.
Modified: mgmt/cumin/python/wooly/server.py
===================================================================
--- mgmt/cumin/python/wooly/server.py 2008-04-14 14:23:46 UTC (rev 1905)
+++ mgmt/cumin/python/wooly/server.py 2008-04-14 15:47:46 UTC (rev 1906)
@@ -37,8 +37,8 @@
session.unmarshal_url_vars(env["QUERY_STRING"])
if "HTTP_AUTHORIZATION" in env:
- str = env["HTTP_AUTHORIZATION"].split(" ")[1]
- name, password = decodestring(str).split(":", 1)
+ auth = env["HTTP_AUTHORIZATION"].split(" ")[1]
+ name, password = decodestring(auth).split(":", 1)
session.credentials["name"] = name
session.credentials["password"] = password
@@ -68,20 +68,18 @@
redirect = page.get_redirect_url(session)
if redirect:
- respond("303 See Other", [("Location", redirect)])
+ respond("303 See Other", (("Location", redirect),))
return ()
-# ims = self.headers.getheader("if-modified-since")
-# modified = page.get_last_modified(session).replace \
-# (microsecond=0)
+ ims = env.get("HTTP_IF_MODIFIED_SINCE")
+ modified = page.get_last_modified(session).replace(microsecond=0)
-# if ims:
-# since = datetime(*strptime(str(ims), self.http_date)[0:6])
+ if ims:
+ since = datetime(*strptime(str(ims), self.http_date)[0:6])
-# if modified <= since:
-# self.send_response(304)
-# self.end_headers()
-# return
+ if modified <= since:
+ respond("304 Not Modified", ())
+ return ()
try:
response = page.render(session)
@@ -89,10 +87,11 @@
return self.error(session, respond)
headers = list()
+ headers.append(("Content-Length", str(len(response))))
-# if modified:
-# ts = modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
-# list.append(("Last-Modified", ts))
+ if modified:
+ ts = modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
+ headers.append(("Last-Modified", ts))
type = page.get_content_type(session)
Show replies by date