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