Commit acccb51e authored by carignani's avatar carignani
Browse files

fixed proxy URL issue and improved error messages

parent 15a4f039
......@@ -13,8 +13,37 @@ import config
import tosca2doc
import doc2tosca
app = Flask(__name__)
class ReverseProxied(object):
def __init__(self, app, script_name=None, scheme=None, server=None): = app
self.script_name = script_name
self.scheme = scheme
self.server = server
print("Reverse Proxy set up")
def __call__(self, environ, start_response):
print("ReverseProxy called")
script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.script_name
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
scheme = environ.get('HTTP_X_SCHEME', '') or self.scheme
if scheme:
environ['wsgi.url_scheme'] = scheme
server = environ.get('HTTP_X_FORWARDED_HOST', '') or self.server
print('HTTP_X_FORWARDED_FOR ' + environ.get('HTTP_X_FORWARDED_FOR'))
if server:
environ['HTTP_HOST'] = server
return, start_response)
app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app, script_name='/tosca-ie')
UPLOAD_FOLDER = '/tmp/upload'
......@@ -59,8 +88,8 @@ def tosca2doc_info():
def mk_tosca2doc():
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
flash('Error: No file uploaded.')
return redirect("/tosca-ie")
......@@ -75,15 +104,15 @@ def mk_tosca2doc():
# print
# print "-------------------"
if not found:
flash('No file part')
print('No file part')
return redirect("/")
flash('Error: some TOSCA module missing. Make sure to upload definitions for NSD, VNFD, PNFD.')
print('Error: TOSCA module missing.')
return redirect("/tosca-ie")
for file in ufiles:
if file.filename == '':
print('No selected file')
flash('No selected file')
return redirect("/")
print('Error: No selected file')
flash('Error: No file uploaded or wrong name.')
return redirect("/tosca-ie")
tmp_dir = tempfile.mkdtemp()
g.tmp_dir = tmp_dir
......@@ -164,4 +193,4 @@ def mk_doc2tosca():
return send_file(zip_path, as_attachment=True)
if __name__ == '__main__':,host='')
\ No newline at end of file,host='')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment