Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(34443)

Side by Side Diff: Lib/http/server.py

Issue 10980: http.server Header Unicode Bug
Patch Set: Created 8 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_httpservers.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """HTTP server classes. 1 """HTTP server classes.
2 2
3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see 3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see
4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, 4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST,
5 and CGIHTTPRequestHandler for CGI scripts. 5 and CGIHTTPRequestHandler for CGI scripts.
6 6
7 It does, however, optionally implement HTTP/1.1 persistent connections, 7 It does, however, optionally implement HTTP/1.1 persistent connections,
8 as of version 0.3. 8 as of version 0.3.
9 9
10 Notes on CGIHTTPRequestHandler 10 Notes on CGIHTTPRequestHandler
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 def send_response_only(self, code, message=None): 442 def send_response_only(self, code, message=None):
443 """Send the response header only.""" 443 """Send the response header only."""
444 if message is None: 444 if message is None:
445 if code in self.responses: 445 if code in self.responses:
446 message = self.responses[code][0] 446 message = self.responses[code][0]
447 else: 447 else:
448 message = '' 448 message = ''
449 if self.request_version != 'HTTP/0.9': 449 if self.request_version != 'HTTP/0.9':
450 self.wfile.write(("%s %d %s\r\n" % 450 self.wfile.write(("%s %d %s\r\n" %
451 (self.protocol_version, code, message)).encode('AS CII', 'strict')) 451 (self.protocol_version, code, message)).encode('la tin1', 'strict'))
452 452
453 def send_header(self, keyword, value): 453 def send_header(self, keyword, value):
454 """Send a MIME header.""" 454 """Send a MIME header."""
455 if self.request_version != 'HTTP/0.9': 455 if self.request_version != 'HTTP/0.9':
456 if not hasattr(self, '_headers_buffer'): 456 if not hasattr(self, '_headers_buffer'):
457 self._headers_buffer = [] 457 self._headers_buffer = []
458 self._headers_buffer.append( 458 self._headers_buffer.append(
459 ("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict')) 459 ("%s: %s\r\n" % (keyword, value)).encode('latin1', 'strict'))
460 460
461 if keyword.lower() == 'connection': 461 if keyword.lower() == 'connection':
462 if value.lower() == 'close': 462 if value.lower() == 'close':
463 self.close_connection = 1 463 self.close_connection = 1
464 elif value.lower() == 'keep-alive': 464 elif value.lower() == 'keep-alive':
465 self.close_connection = 0 465 self.close_connection = 0
466 466
467 def end_headers(self): 467 def end_headers(self):
468 """Send the blank line ending the MIME headers.""" 468 """Send the blank line ending the MIME headers."""
469 if self.request_version != 'HTTP/0.9': 469 if self.request_version != 'HTTP/0.9':
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 print("Serving HTTP on", sa[0], "port", sa[1], "...") 1177 print("Serving HTTP on", sa[0], "port", sa[1], "...")
1178 try: 1178 try:
1179 httpd.serve_forever() 1179 httpd.serve_forever()
1180 except KeyboardInterrupt: 1180 except KeyboardInterrupt:
1181 print("\nKeyboard interrupt received, exiting.") 1181 print("\nKeyboard interrupt received, exiting.")
1182 httpd.server_close() 1182 httpd.server_close()
1183 sys.exit(0) 1183 sys.exit(0)
1184 1184
1185 if __name__ == '__main__': 1185 if __name__ == '__main__':
1186 test(HandlerClass=SimpleHTTPRequestHandler) 1186 test(HandlerClass=SimpleHTTPRequestHandler)
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_httpservers.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+