mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 22:54:23 +01:00
Logs real IP if API is behind a reverse proxy
This commit is contained in:
20
pisa/api.py
20
pisa/api.py
@@ -35,10 +35,12 @@ class API:
|
|||||||
can be found at :mod:`Errors <pisa.errors>`.
|
can be found at :mod:`Errors <pisa.errors>`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Getting the real IP if the server is behind a reverse proxy
|
||||||
|
remote_addr = request.environ.get("HTTP_X_REAL_IP")
|
||||||
|
if not remote_addr:
|
||||||
remote_addr = request.environ.get("REMOTE_ADDR")
|
remote_addr = request.environ.get("REMOTE_ADDR")
|
||||||
remote_port = request.environ.get("REMOTE_PORT")
|
|
||||||
|
|
||||||
logger.info("Received add_appointment request", from_addr_port="{}:{}".format(remote_addr, remote_port))
|
logger.info("Received add_appointment request", from_addr="{}".format(remote_addr))
|
||||||
|
|
||||||
if request.is_json:
|
if request.is_json:
|
||||||
# Check content type once if properly defined
|
# Check content type once if properly defined
|
||||||
@@ -77,10 +79,7 @@ class API:
|
|||||||
response = None
|
response = None
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Sending response and disconnecting",
|
"Sending response and disconnecting", from_addr="{}".format(remote_addr), response=response, error=error
|
||||||
from_addr_port="{}:{}".format(remote_addr, remote_port),
|
|
||||||
response=response,
|
|
||||||
error=error,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if error is None:
|
if error is None:
|
||||||
@@ -106,15 +105,16 @@ class API:
|
|||||||
- Appointments hold by the :obj:`Responder <pisa.responder.Responder>` are flagged as ``dispute_triggered``.
|
- Appointments hold by the :obj:`Responder <pisa.responder.Responder>` are flagged as ``dispute_triggered``.
|
||||||
- Unknown appointments are flagged as ``not_found``.
|
- Unknown appointments are flagged as ``not_found``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Getting the real IP if the server is behind a reverse proxy
|
||||||
|
remote_addr = request.environ.get("HTTP_X_REAL_IP")
|
||||||
|
if not remote_addr:
|
||||||
remote_addr = request.environ.get("REMOTE_ADDR")
|
remote_addr = request.environ.get("REMOTE_ADDR")
|
||||||
remote_port = request.environ.get("REMOTE_PORT")
|
|
||||||
|
|
||||||
locator = request.args.get("locator")
|
locator = request.args.get("locator")
|
||||||
response = []
|
response = []
|
||||||
|
|
||||||
logger.info(
|
logger.info("Received get_appointment request", from_addr="{}".format(remote_addr), locator=locator)
|
||||||
"Received get_appointment request", from_addr_port="{}:{}".format(remote_addr, remote_port), locator=locator
|
|
||||||
)
|
|
||||||
|
|
||||||
# ToDo: #15-add-system-monitor
|
# ToDo: #15-add-system-monitor
|
||||||
if not isinstance(locator, str) or len(locator) != LOCATOR_LEN_HEX:
|
if not isinstance(locator, str) or len(locator) != LOCATOR_LEN_HEX:
|
||||||
|
|||||||
Reference in New Issue
Block a user