Changeset 1402
- Timestamp:
- 10/20/06 02:14:06
- Files:
-
- trunk/cherrypy/lib/cptools.py (modified) (2 diffs)
- trunk/cherrypy/lib/encoding.py (modified) (2 diffs)
- trunk/cherrypy/lib/static.py (modified) (2 diffs)
- trunk/cherrypy/lib/tidy.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/cptools.py
r1369 r1402 211 211 body = self.login_screen(from_page, username, error_msg) 212 212 cherrypy.response.body = body 213 if cherrypy.response.headers.has_key("Content-Length"): 214 # Delete Content-Length header so finalize() recalcs it. 215 del cherrypy.response.headers["Content-Length"] 213 216 return True 214 217 else: … … 236 239 if not username: 237 240 cherrypy.response.body = self.login_screen(cherrypy.url(qs=request.query_string)) 241 if cherrypy.response.headers.has_key("Content-Length"): 242 # Delete Content-Length header so finalize() recalcs it. 243 del cherrypy.response.headers["Content-Length"] 238 244 return True 239 245 trunk/cherrypy/lib/encoding.py
r1391 r1402 101 101 response.collapse_body() 102 102 encoder = encode_string 103 if response.headers.has_key("Content-Length"): 104 # Delete Content-Length header so finalize() recalcs it. 105 # Encoded strings may be of different lengths from their 106 # unicode equivalents, and even from each other. For example: 107 # >>> t = u"\u7007\u3040" 108 # >>> len(t) 109 # 2 110 # >>> len(t.encode("UTF-8")) 111 # 6 112 # >>> len(t.encode("utf7")) 113 # 8 114 del response.headers["Content-Length"] 103 115 104 116 # Parse the Accept-Charset request header, and try to provide one … … 218 230 response.headers['Content-Encoding'] = 'gzip' 219 231 response.body = compress(response.body, compress_level) 232 if response.headers.has_key("Content-Length"): 233 # Delete Content-Length header so finalize() recalcs it. 234 del response.headers["Content-Length"] 220 235 return 221 236 cherrypy.HTTPError(406, "identity, gzip").set_response() trunk/cherrypy/lib/static.py
r1401 r1402 18 18 """Set status, headers, and body in order to serve the given file. 19 19 20 The Content-Type header will be set to the content_ ype arg, if provided.20 The Content-Type header will be set to the content_type arg, if provided. 21 21 If not provided, the Content-Type will be guessed by its extension. 22 22 … … 97 97 ct = "multipart/byteranges; boundary=%s" % boundary 98 98 response.headers['Content-Type'] = ct 99 ## del response.headers['Content-Length'] 99 if response.headers.has_key("Content-Length"): 100 # Delete Content-Length header so finalize() recalcs it. 101 del response.headers["Content-Length"] 100 102 101 103 def file_ranges(): trunk/cherrypy/lib/tidy.py
r1313 r1402 19 19 server would also crash) 20 20 """ 21 response = cherrypy.response 22 21 23 # the tidy tool, by its very nature it's not generator friendly, 22 24 # so we just collapse the body and work with it. 23 orig_body = cherrypy.response.collapse_body()25 orig_body = response.collapse_body() 24 26 25 fct = cherrypy.response.headers.get('Content-Type', '')27 fct = response.headers.get('Content-Type', '') 26 28 ct = fct.split(';')[0] 27 29 encoding = '' … … 74 76 75 77 if new_errs: 76 cherrypy.response.body = wrong_content('<br />'.join(new_errs), 77 orig_body) 78 response.body = wrong_content('<br />'.join(new_errs), orig_body) 79 if response.headers.has_key("Content-Length"): 80 # Delete Content-Length header so finalize() recalcs it. 81 del response.headers["Content-Length"] 78 82 return 79 83 elif strict_xml: … … 97 101 traceback.print_exc(file = body_file) 98 102 body_file = '<br />'.join(body_file.getvalue()) 99 cherrypy.response.body = wrong_content(body_file, orig_body, "XML") 103 response.body = wrong_content(body_file, orig_body, "XML") 104 if response.headers.has_key("Content-Length"): 105 # Delete Content-Length header so finalize() recalcs it. 106 del response.headers["Content-Length"] 100 107 return 101 108 102 109 if use_output: 103 cherrypy.response.body = [output] 110 response.body = [output] 111 if response.headers.has_key("Content-Length"): 112 # Delete Content-Length header so finalize() recalcs it. 113 del response.headers["Content-Length"] 104 114 105 115 def html_space(text): … … 119 129 120 130 def nsgmls(temp_dir, nsgmls_path, catalog_path, errors_to_ignore=None): 131 response = cherrypy.response 132 121 133 # the tidy tool, by its very nature it's not generator friendly, 122 134 # so we just collect the body and work with it. 123 orig_body = cherrypy.response.collapse_body()135 orig_body = response.collapse_body() 124 136 125 fct = cherrypy.response.headers.get('Content-Type', '')137 fct = response.headers.get('Content-Type', '') 126 138 ct = fct.split(';')[0] 127 139 encoding = '' … … 163 175 164 176 if new_errs: 165 cherrypy.response.body = wrong_content('<br />'.join(new_errs), 166 orig_body) 177 response.body = wrong_content('<br />'.join(new_errs), orig_body) 178 if response.headers.has_key("Content-Length"): 179 # Delete Content-Length header so finalize() recalcs it. 180 del response.headers["Content-Length"] 167 181

