Anonymous avatar Anonymous committed 0a74e8c

fixes for ticket #149 and #121

Comments (0)

Files changed (1)

     parseFirstLine(requestLine)
     cookHeaders(clientAddress, remoteHost, headers, requestLine)
 
-    cpg.request.base = "http://" + cpg.request.headerMap['Host']
+    cpg.request.base = "http://" + cpg.request.headerMap.get('Host', '')
     cpg.request.browserUrl = cpg.request.base + cpg.request.browserUrl
     cpg.request.isStatic = False
     cpg.request.parsePostData = True
 
     applyFilterList('afterRequestBody')
 
-def doRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile):
-    # creates some attributes on cpg.response so filters can use them
-    cpg.response.wfile = wfile
-    cpg.response.sendResponse = 1
-    try:
-        initRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile)
-    except basefilter.RequestHandled:
-        # request was already fully handled; it may be a cache hit
-        return
-
-    # Prepare response variables
-    now = time.time()
-    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(now)
-    date = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekdayname[wd], day, monthname[month], year, hh, mm, ss)
-    cpg.response.headerMap = {
-        "protocolVersion": cpg.configOption.protocolVersion,
-        "Status": "200 OK",
-        "Content-Type": "text/html",
-        "Server": "CherryPy/" + cpg.__version__,
-        "Date": date,
-        "Set-Cookie": [],
-        "Content-Length": 0
-    }
-    cpg.response.simpleCookie = Cookie.SimpleCookie()
-
-    try:
+def doRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile):
+    # creates some attributes on cpg.response so filters can use them
+    cpg.response.wfile = wfile
+    cpg.response.sendResponse = 1
+    # Prepare response variables
+    now = time.time()
+    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(now)
+    date = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekdayname[wd], day, monthname[month], year, hh, mm, ss)
+    cpg.response.headerMap = {
+        "protocolVersion": cpg.configOption.protocolVersion,
+        "Status": "200 OK",
+        "Content-Type": "text/html",
+        "Server": "CherryPy/" + cpg.__version__,
+        "Date": date,
+        "Set-Cookie": [],
+        "Content-Length": 0
+    }
+    cpg.response.simpleCookie = Cookie.SimpleCookie()
+    try:
+        try:
+            initRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile)
+        except basefilter.RequestHandled:
+            # request was already fully handled; it may be a cache hit
+            return
+        except:
+            # exception raised in a filter.
+            # we don't have a response body yet, so create an empty one
+            cpg.response.body = []
+            raise
         handleRequest(cpg.response.wfile)
     except:
         # TODO: in some cases exceptions and filters are conflicting; 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.