Source code for server.proxy_helpers

from flask import request, current_app


behind_proxy_options = (None, "nginx", "npm")

[docs] def real_remote_addr(): """Returns the real remote IP address. Uses BEHIND_PROXY config setting. When the app is not behind a proxy (BEHIND_PROXY==None), the returned address is just request.remote_addr. Otherwise, the real address must be retrieved from a special header set by the proxy service. """ proxy = current_app.config.get("BEHIND_PROXY") if proxy in (None, "npm"): return request.remote_addr elif str(proxy).lower() == "nginx": return request.headers.get("X-Real-IP", "<Missing X-Real-IP header!>") else: return "<Bad BEHIND_PROXY config!>"