| | 193 | |
|---|
| | 194 | def _cpOnHTTPError(status, message): |
|---|
| | 195 | """ Default _cpOnHTTPError method. |
|---|
| | 196 | |
|---|
| | 197 | status should be an int. |
|---|
| | 198 | """ |
|---|
| | 199 | tb = formatExc() |
|---|
| | 200 | if cherrypy.config.get('server.logTracebacks', True): |
|---|
| | 201 | cherrypy.log(tb) |
|---|
| | 202 | |
|---|
| | 203 | if not cherrypy.config.get('server.showTracebacks', False): |
|---|
| | 204 | tb = None |
|---|
| | 205 | |
|---|
| | 206 | response = cherrypy.response |
|---|
| | 207 | |
|---|
| | 208 | # Remove headers which applied to the original content, |
|---|
| | 209 | # but do not apply to the error page. |
|---|
| | 210 | for key in ["Accept-Ranges", "Age", "ETag", "Location", |
|---|
| | 211 | "Retry-After", "Vary", "Content-Encoding", |
|---|
| | 212 | "Content-Length", "Content-Location", "Content-MD5", |
|---|
| | 213 | "Expires", "Last-Modified"]: |
|---|
| | 214 | if response.headerMap.has_key(key): |
|---|
| | 215 | del response.headerMap[key] |
|---|
| | 216 | |
|---|
| | 217 | if status != 416: |
|---|
| | 218 | # A server sending a response with status code 416 (Requested |
|---|
| | 219 | # range not satisfiable) SHOULD include a Content-Range field |
|---|
| | 220 | # with a byte-range- resp-spec of "*". The instance-length |
|---|
| | 221 | # specifies the current length of the selected resource. |
|---|
| | 222 | # A response with status code 206 (Partial Content) MUST NOT |
|---|
| | 223 | # include a Content-Range field with a byte-range- resp-spec of "*". |
|---|
| | 224 | if response.headerMap.has_key("Content-Range"): |
|---|
| | 225 | del response.headerMap["Content-Range"] |
|---|
| | 226 | |
|---|
| | 227 | # In all cases, finalize will be called after this method, |
|---|
| | 228 | # so don't bother cleaning up response values here. |
|---|
| | 229 | response.status = status |
|---|
| | 230 | response.headerMap['Content-Type'] = "text/html" |
|---|
| | 231 | response.body = getErrorPage(status, traceback=tb, message=message) |
|---|