diff options
author | B Stack <bgstack15@gmail.com> | 2021-09-24 15:17:35 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2021-09-24 15:17:35 -0400 |
commit | d960f0cef937ae8a4a19e4dfaf3c617f1e93b10c (patch) | |
tree | 3a858b0e1c9fba106174052e85dfceff41398abe /fuss.py | |
parent | fix some building details for el7 (diff) | |
download | fuss-d960f0cef937ae8a4a19e4dfaf3c617f1e93b10c.tar.gz fuss-d960f0cef937ae8a4a19e4dfaf3c617f1e93b10c.tar.bz2 fuss-d960f0cef937ae8a4a19e4dfaf3c617f1e93b10c.zip |
fix x-forwarded-prefix header consumption
Now that I have experimented with X-Forwarded-Prefix and reverse
proxies, this logic works correctly now!
Diffstat (limited to 'fuss.py')
-rw-r--r-- | fuss.py | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -21,7 +21,7 @@ from flask_script import Manager, Server # python3-flask-script import magic # python3-magic, see below from hashlib import sha256 from mimetypes import guess_extension -import os, sys, time, json, base64 +import os, sys, time, json, base64, re from datetime import datetime, date from uwsgidecorators import * # python3-uwsgidecorators from logging.config import dictConfig @@ -48,6 +48,9 @@ def trim_dict(a,max_length=40): b[i] = a[i] return b +def normalize(instring): + return re.sub("//","/",instring) + # load config file # Load it from the current directory, which is not FHS-compliant #conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"fuss.conf") @@ -266,9 +269,10 @@ def print_files(path=None,format="text",header=False): _server = "http://" + request.headers["Host"] try: _prefix = request.headers["X-Forwarded-Prefix"] + #app.logger.warn("This is x-forwarded-prefix: {0}".format(request.headers["X-Forwarded-Prefix"])) # REMOVEME _temp = _prefix.replace(", ", "\n").split('\n') - if len(_temp) > 1: - _prefix = _temp[0] + _temp = normalize("/".join(_temp)) + _prefix = _temp except: _prefix = "/" app.logger.warn("Failed to get x-forwarded-prefix") @@ -453,9 +457,10 @@ def html_template(filename="",full=False): _server = "http://" + request.headers["Host"] try: _prefix = request.headers["X-Forwarded-Prefix"] + #app.logger.warn("This is x-forwarded-prefix: {0}".format(request.headers["X-Forwarded-Prefix"])) # REMOVEME _temp = _prefix.replace(", ", "\n").split('\n') - if len(_temp) > 1: - _prefix = _temp[0] + _temp = normalize("/".join(_temp)) + _prefix = _temp except: _prefix = "/" if full: |