.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.flaskfix.ReverseProxyPathFix Class Reference

Public Member Functions

 __init__ (self, wsgi_app)
 __call__ (self, environ, start_response)

Public Attributes

 wsgi_app = wsgi_app
 script_name = None
 scheme = None
 server = None

Detailed Description

Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.

http://flask.pocoo.org/snippets/35/

In nginx:
location /myprefix {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Script-Name /myprefix;
    }

:param wsgi_app: the WSGI application

Definition at line 11 of file flaskfix.py.

Constructor & Destructor Documentation

◆ __init__()

searx.flaskfix.ReverseProxyPathFix.__init__ ( self,
wsgi_app )

Definition at line 33 of file flaskfix.py.

33 def __init__(self, wsgi_app):
34
35 self.wsgi_app = wsgi_app
36 self.script_name = None
37 self.scheme = None
38 self.server = None
39
40 if settings['server']['base_url']:
41
42 # If base_url is specified, then these values from are given
43 # preference over any Flask's generics.
44
45 base_url = urlparse(settings['server']['base_url'])
46 self.script_name = base_url.path
47 if self.script_name.endswith('/'):
48 # remove trailing slash to avoid infinite redirect on the index
49 # see https://github.com/searx/searx/issues/2729
50 self.script_name = self.script_name[:-1]
51 self.scheme = base_url.scheme
52 self.server = base_url.netloc
53

Member Function Documentation

◆ __call__()

searx.flaskfix.ReverseProxyPathFix.__call__ ( self,
environ,
start_response )

Definition at line 54 of file flaskfix.py.

54 def __call__(self, environ, start_response):
55 script_name = self.script_name or environ.get('HTTP_X_SCRIPT_NAME', '')
56 if script_name:
57 environ['SCRIPT_NAME'] = script_name
58 path_info = environ['PATH_INFO']
59 if path_info.startswith(script_name):
60 environ['PATH_INFO'] = path_info[len(script_name) :]
61
62 scheme = self.scheme or environ.get('HTTP_X_SCHEME') or environ.get('HTTP_X_FORWARDED_PROTO')
63 if scheme:
64 environ['wsgi.url_scheme'] = scheme
65
66 server = self.server or environ.get('HTTP_X_FORWARDED_HOST', '')
67 if server:
68 environ['HTTP_HOST'] = server
69 return self.wsgi_app(environ, start_response)
70
71

References scheme, script_name, server, searx.botdetection.trusted_proxies.ProxyFix.wsgi_app, and wsgi_app.

Member Data Documentation

◆ scheme

searx.flaskfix.ReverseProxyPathFix.scheme = None

Definition at line 37 of file flaskfix.py.

Referenced by __call__().

◆ script_name

searx.flaskfix.ReverseProxyPathFix.script_name = None

Definition at line 36 of file flaskfix.py.

Referenced by __call__().

◆ server

searx.flaskfix.ReverseProxyPathFix.server = None

Definition at line 38 of file flaskfix.py.

Referenced by __call__().

◆ wsgi_app

searx.flaskfix.ReverseProxyPathFix.wsgi_app = wsgi_app

Definition at line 35 of file flaskfix.py.

Referenced by __call__().


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/flaskfix.py