OLD | NEW |
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 import argparse | 3 import argparse |
4 import re | 4 import re |
5 import sys | 5 import sys |
6 import threading | 6 import threading |
7 import traceback | 7 import traceback |
8 | 8 |
9 from http.server import BaseHTTPRequestHandler, HTTPServer | 9 from http.server import BaseHTTPRequestHandler, HTTPServer |
10 from string import Template | 10 from string import Template |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 def write_info(self, args): | 34 def write_info(self, args): |
35 message = Template(self.format).safe_substitute(args) + '\n' | 35 message = Template(self.format).safe_substitute(args) + '\n' |
36 with _lock: | 36 with _lock: |
37 self.output.write(message) | 37 self.output.write(message) |
38 self.output.flush() | 38 self.output.flush() |
39 | 39 |
40 def do_POST(self): | 40 def do_POST(self): |
41 status = 200 | 41 status = 200 |
42 content = bytes(self.response, 'UTF-8') | 42 content = bytes(self.response, 'UTF-8') |
| 43 body_len = int(self.headers.get('content-length', 0)) |
| 44 body = self.rfile.read(body_len).decode('UTF-8') |
43 values = { | 45 values = { |
44 'remote_addr': self.address_string(), | 46 'remote_addr': self.address_string(), |
45 'time_local': self.log_date_time_string(), | 47 'time_local': self.log_date_time_string(), |
46 'request': self.requestline, | 48 'request': self.requestline, |
47 'status': status, | 49 'status': status, |
48 'bytes_sent': len(content), | 50 'bytes_sent': len(content), |
| 51 'body': body, |
49 } | 52 } |
50 values.update(self.get_header_values()) | 53 values.update(self.get_header_values()) |
51 try: | 54 try: |
52 self.write_info(values) | 55 self.write_info(values) |
53 self.send_simple_response(status, content) | 56 self.send_simple_response(status, content) |
54 except: | 57 except: |
55 traceback.print_exc(file=sys.stderr) | 58 traceback.print_exc(file=sys.stderr) |
56 self.send_simple_response(500) | 59 self.send_simple_response(500) |
57 | 60 |
58 | 61 |
(...skipping 20 matching lines...) Expand all Loading... |
79 fh = open(sys.stdout.fileno(), 'w', closefd=False) | 82 fh = open(sys.stdout.fileno(), 'w', closefd=False) |
80 try: | 83 try: |
81 Handler.output = fh | 84 Handler.output = fh |
82 Handler.format = args.format | 85 Handler.format = args.format |
83 Handler.response = args.response | 86 Handler.response = args.response |
84 server_address = ('', args.port) | 87 server_address = ('', args.port) |
85 httpd = HTTPServer(server_address, Handler) | 88 httpd = HTTPServer(server_address, Handler) |
86 httpd.serve_forever() | 89 httpd.serve_forever() |
87 finally: | 90 finally: |
88 fh.close() | 91 fh.close() |
OLD | NEW |