mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make information on the remote client available to HTTP handlers
This commit is contained in:
parent
1bc5dfc47f
commit
3b308e3d41
@ -180,10 +180,11 @@ def get_range_parts(ranges, content_type, content_length): # {{{
|
|||||||
|
|
||||||
class RequestData(object): # {{{
|
class RequestData(object): # {{{
|
||||||
|
|
||||||
def __init__(self, method, path, query, inheaders, request_body_file, outheaders, response_protocol, static_cache, opts):
|
def __init__(self, method, path, query, inheaders, request_body_file, outheaders, response_protocol, static_cache, opts, remote_addr, remote_port):
|
||||||
self.method, self.path, self.query, self.inheaders, self.request_body_file, self.outheaders, self.response_protocol, self.static_cache = (
|
self.method, self.path, self.query, self.inheaders, self.request_body_file, self.outheaders, self.response_protocol, self.static_cache = (
|
||||||
method, path, query, inheaders, request_body_file, outheaders, response_protocol, static_cache
|
method, path, query, inheaders, request_body_file, outheaders, response_protocol, static_cache
|
||||||
)
|
)
|
||||||
|
self.remote_addr, self.remote_port = remote_addr, remote_port
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
self.status_code = httplib.CREATED if self.method == 'POST' else httplib.OK
|
self.status_code = httplib.CREATED if self.method == 'POST' else httplib.OK
|
||||||
|
|
||||||
@ -310,7 +311,11 @@ class HTTPConnection(HTTPRequest):
|
|||||||
return self.simple_response(httplib.OK, msg, close_after_response=False)
|
return self.simple_response(httplib.OK, msg, close_after_response=False)
|
||||||
request_body_file.seek(0)
|
request_body_file.seek(0)
|
||||||
outheaders = MultiDict()
|
outheaders = MultiDict()
|
||||||
data = RequestData(self.method, self.path, self.query, inheaders, request_body_file, outheaders, self.response_protocol, self.static_cache, self.opts)
|
data = RequestData(
|
||||||
|
self.method, self.path, self.query, inheaders, request_body_file,
|
||||||
|
outheaders, self.response_protocol, self.static_cache, self.opts,
|
||||||
|
self.remote_addr, self.remote_port
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
output = self.request_handler(data)
|
output = self.request_handler(data)
|
||||||
except HTTP404 as e:
|
except HTTP404 as e:
|
||||||
|
@ -111,8 +111,14 @@ class ReadBuffer(object): # {{{
|
|||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
|
|
||||||
def __init__(self, socket, opts, ssl_context, tdir):
|
def __init__(self, socket, opts, ssl_context, tdir, addr):
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
try:
|
||||||
|
self.remote_addr = addr[0]
|
||||||
|
self.remote_port = addr[1]
|
||||||
|
except Exception:
|
||||||
|
# In case addr is None, which can occassionally happen
|
||||||
|
self.remote_addr = self.remote_port = None
|
||||||
self.orig_send_bufsize = self.send_bufsize = 4096
|
self.orig_send_bufsize = self.send_bufsize = 4096
|
||||||
self.tdir = tdir
|
self.tdir = tdir
|
||||||
self.ssl_context = ssl_context
|
self.ssl_context = ssl_context
|
||||||
@ -471,7 +477,7 @@ class ServerLoop(object):
|
|||||||
if sock is not None:
|
if sock is not None:
|
||||||
s = sock.fileno()
|
s = sock.fileno()
|
||||||
if s > -1:
|
if s > -1:
|
||||||
self.connection_map[s] = conn = self.handler(sock, self.opts, self.ssl_context, self.tdir)
|
self.connection_map[s] = conn = self.handler(sock, self.opts, self.ssl_context, self.tdir, addr)
|
||||||
if self.ssl_context is not None:
|
if self.ssl_context is not None:
|
||||||
yield s, conn, RDWR
|
yield s, conn, RDWR
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user