Changeset 815
- Timestamp:
- 11/12/05 06:55:17
- Files:
-
- trunk/cherrypy/_cphttptools.py (modified) (1 diff)
- trunk/cherrypy/_cputil.py (modified) (3 diffs)
- trunk/cherrypy/config.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttptools.py
r812 r815 63 63 # right away. 64 64 self.processRequestLine(requestLine) 65 66 # if we receive OPTIONS * HTTP/1.1 67 # then we should simply answer right away 68 if self.method == 'OPTIONS': 69 # this normally should be * but processRequestLine 70 # switched it to 'global' for the configuration handling 71 if self.path == 'global': 72 # OPTIONS is defined in HTTP 1.1 73 response = cherrypy.response 74 if response.version >= '1.1': 75 response.body = [] 76 response.status = '200 OK' 77 response.headerMap['Allow'] = 'HEAD, GET, POST, PUT, OPTIONS' 78 response.headerMap['Content-Length'] = 0 79 response.headerMap['Content-Type'] = 'text/plain' 80 response.finalize() 81 _cputil.getSpecialAttribute("_cpLogAccess")() 82 return 65 66 # handles "OPTIONS * HTTP/1.1" requests 67 # we could avoid testing for the method value here but 68 # we still do it to avoid an useless call to getSpecialAttribute 69 # OPTIONS request should be very rare compare to regular requests 70 # let's not add too much overhead 71 if cherrypy.request.method == 'OPTIONS': 72 if _cputil.getSpecialAttribute("_cpGlobalInformation")() == True: 73 # if we had such a request we don't have to keep processing 74 return 83 75 84 76 try: trunk/cherrypy/_cputil.py
r807 r815 71 71 raise cherrypy.HTTPError(500, msg) 72 72 73 def _cpGlobalInformation(): 74 """Handles OPTIONS * HTTP/1.1 requests""" 75 request = cherrypy.request 76 if request.method == 'OPTIONS': 77 # this normally should be * but processRequestLine 78 # switched it to 'global' for the configuration handling 79 if request.path == 'global': 80 # OPTIONS is defined in HTTP 1.1 81 if request.version >= '1.1': 82 response = cherrypy.response 83 response.body = [] 84 response.status = '200 OK' 85 response.headerMap['Allow'] = 'HEAD, GET, POST, PUT, OPTIONS' 86 response.headerMap['Content-Length'] = 0 87 response.headerMap['Content-Type'] = 'text/plain' 88 response.finalize() 89 getSpecialAttribute("_cpLogAccess")() 90 return True 91 return False 92 73 93 def logtime(): 74 94 return '%04d/%02d/%02d %02d:%02d:%02d' % time.localtime(time.time())[:6] … … 103 123 104 124 level = _log_severity_levels.get(severity, "UNKNOWN") 105 s = logtime() + ' ' + context + ' ' + level + ' ' + msg 125 126 requestheaders = '' 127 if cherrypy.config.get('server.showRequestHeaders', True): 128 requestheaders = format_request_headers() 129 130 s = ' '.join((logtime(), context, level, requestheaders, msg)) 106 131 107 132 if cherrypy.config.get('server.logToScreen', True): … … 273 298 return "".join(traceback.format_exception(*exc)) 274 299 300 def format_request_headers(): 301 """returns the list of request headers as a string separated by new lines, one header on each line""" 302 if hasattr(cherrypy.request, 'headerMap'): 303 headers = '\n'.join(': '.join((header, value)) for header, value in cherrypy.request.headerMap.items()) 304 return ''.join(('\n', headers, '\n', '\n')) 305 return '' 306 275 307 def bareError(extrabody=None): 276 308 """Produce status, headers, body for a critical error. trunk/cherrypy/config.py
r807 r815 31 31 'server.logFileNotFound': True, 32 32 'server.showTracebacks': True, 33 'server.showRequestHeaders': True, 33 34 }, 34 35 "staging": { … … 37 38 'server.logFileNotFound': False, 38 39 'server.showTracebacks': False, 40 'server.showRequestHeaders': False, 39 41 }, 40 42 "production": { … … 43 45 'server.logFileNotFound': False, 44 46 'server.showTracebacks': False, 47 'server.showRequestHeaders': False, 45 48 }, 46 49 }

