From ea1f93282ffe6f2542eebe5ebf1c39057598679a Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Tue, 25 Oct 2022 19:20:49 +0200 Subject: [PATCH] Move query wrapper to a separate function --- bin/proxy.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/bin/proxy.py b/bin/proxy.py index eda8def..0f7a645 100755 --- a/bin/proxy.py +++ b/bin/proxy.py @@ -273,18 +273,8 @@ def _fetch_content_and_headers(path, query_string, **kwargs): return content, headers -@APP.route("/") -def proxy(path): - """ - Main proxy function. Handles incoming HTTP queries. - """ +def _make_query(path, query_string): - lang = request.args.get('lang', 'en') - query_string = request.query_string.decode("utf-8") - query_string = query_string.replace('sr-lat', 'sr') - query_string = query_string.replace('lang=None', 'lang=en') - content = "" - headers = "" if _is_metno(): path, query, days = metno_request(path, query_string) if USER_AGENT == '': @@ -299,6 +289,25 @@ def proxy(path): query_string += "&includelocation=yes" content, headers = _fetch_content_and_headers(path, query_string) + return content, headers + +@APP.route("/") +def proxy(path): + """ + Main proxy function. Handles incoming HTTP queries. + """ + + lang = request.args.get('lang', 'en') + query_string = request.query_string.decode("utf-8") + query_string = query_string.replace('sr-lat', 'sr') + query_string = query_string.replace('lang=None', 'lang=en') + content = "" + headers = "" + + content, headers = _make_query(path, query_string) + + # _log_query(path, query_string, error) + content = add_translations(content, lang) return content, 200, headers @@ -306,6 +315,7 @@ def proxy(path): if __name__ == "__main__": #app.run(host='0.0.0.0', port=5001, debug=False) #app.debug = True + if len(sys.argv) == 1: bind_addr = "0.0.0.0" SERVER = WSGIServer((bind_addr, PROXY_PORT), APP)