wsgi: environ[REMOTE_PORT], also available in log_format, plus log accept event; Thanks to Peter Portante

This commit is contained in:
Sergey Shepelev
2013-01-23 23:15:37 +04:00
parent 178cd4fb89
commit 1720c5bb7c

View File

@@ -18,6 +18,7 @@ MAX_REQUEST_LINE = 8192
MAX_HEADER_LINE = 8192
MAX_TOTAL_HEADER_SIZE = 65536
MINIMUM_CHUNK_SIZE = 4096
# %(client_port)s is also available
DEFAULT_LOG_FORMAT= ('%(client_ip)s - - [%(date_time)s] "%(request_line)s"'
' %(status_code)s %(body_length)s %(wall_seconds).6f')
@@ -431,14 +432,15 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler):
hook(self.environ, *args, **kwargs)
if self.server.log_output:
self.server.log_message(self.server.log_format % dict(
client_ip=self.get_client_ip(),
date_time=self.log_date_time_string(),
request_line=self.requestline,
status_code=status_code[0],
body_length=length[0],
wall_seconds=finish - start))
self.server.log_message(self.server.log_format % {
'client_ip': self.get_client_ip(),
'client_port': self.client_address[1],
'date_time': self.log_date_time_string(),
'request_line': self.requestline,
'status_code': status_code[0],
'body_length': length[0],
'wall_seconds': finish - start,
})
def get_client_ip(self):
client_ip = self.client_address[0]
@@ -473,6 +475,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler):
env['SERVER_NAME'] = host
env['SERVER_PORT'] = str(port)
env['REMOTE_ADDR'] = self.client_address[0]
env['REMOTE_PORT'] = str(self.client_address[1])
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
for h in self.headers.headers:
@@ -654,10 +657,13 @@ def server(sock, site,
port = ''
serv.log.write("(%s) wsgi starting up on %s://%s%s/\n" % (
os.getpid(), scheme, host, port))
serv.pid, scheme, host, port))
while True:
try:
client_socket = sock.accept()
if debug:
serv.log.write("(%s) accepted %r\n" % (
serv.pid, client_socket[1]))
try:
pool.spawn_n(serv.process_request, client_socket)
except AttributeError: