.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-Scheme $scheme;
    proxy_set_header X-Script-Name /myprefix;
    }

:param wsgi_app: the WSGI application

Definition at line 12 of file flaskfix.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 34 of file flaskfix.py.

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

Member Function Documentation

◆ __call__()

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

Definition at line 55 of file flaskfix.py.

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

References searx.flaskfix.ReverseProxyPathFix.scheme, searx.flaskfix.ReverseProxyPathFix.script_name, searx.flaskfix.ReverseProxyPathFix.server, and searx.flaskfix.ReverseProxyPathFix.wsgi_app.

Member Data Documentation

◆ scheme

searx.flaskfix.ReverseProxyPathFix.scheme = None

Definition at line 38 of file flaskfix.py.

Referenced by searx.flaskfix.ReverseProxyPathFix.__call__().

◆ script_name

searx.flaskfix.ReverseProxyPathFix.script_name = None

Definition at line 37 of file flaskfix.py.

Referenced by searx.flaskfix.ReverseProxyPathFix.__call__().

◆ server

searx.flaskfix.ReverseProxyPathFix.server = None

Definition at line 39 of file flaskfix.py.

Referenced by searx.flaskfix.ReverseProxyPathFix.__call__().

◆ wsgi_app

searx.flaskfix.ReverseProxyPathFix.wsgi_app = wsgi_app

Definition at line 36 of file flaskfix.py.

Referenced by searx.flaskfix.ReverseProxyPathFix.__call__().


The documentation for this class was generated from the following file: