From 99f7613c53168fbabfb8f820ee38408966914807 Mon Sep 17 00:00:00 2001 From: maxkoryukov Date: Wed, 20 Apr 2016 06:49:06 +0500 Subject: [PATCH] FIX: an opprotunity to set HTTP-header, used by CherryPy to determine origin url of proxy (when HP works behind proxy) see #rembo10/headphones#2616 --- Headphones.py | 1 + headphones/config/definitions/advanced.py | 31 ++++++++++++++++------- headphones/webstart.py | 7 +++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Headphones.py b/Headphones.py index dc956a43e..229ab28bc 100755 --- a/Headphones.py +++ b/Headphones.py @@ -186,6 +186,7 @@ def main(): 'http_host': headphones.CONFIG.HTTP_HOST, 'http_root': headphones.CONFIG.HTTP_ROOT, 'http_proxy': headphones.CONFIG.HTTP_PROXY, + 'http_proxy_header_host': headphones.CONFIG.HTTP_PROXY_HEADER_HOST, 'enable_https': headphones.CONFIG.ENABLE_HTTPS, 'https_cert': headphones.CONFIG.HTTPS_CERT, 'https_key': headphones.CONFIG.HTTPS_KEY, diff --git a/headphones/config/definitions/advanced.py b/headphones/config/definitions/advanced.py index 7268e2c8d..d6ddb0770 100644 --- a/headphones/config/definitions/advanced.py +++ b/headphones/config/definitions/advanced.py @@ -434,18 +434,31 @@ def reg(_extend_cb): # ======================================================================================= opts.extend([ BlockExtension('advanced_http_paths', caption=_("Advanced HTTP"), options=_extend_cb( - OptionBool('HTTP_PROXY', 'General', False, - label=_('Behind proxy'), - caption=_('Headphones works behind proxy, and should be careful with generated urls'), - ), - OptionString('HTTP_ROOT', 'General', '/', - label=_('HTTP root'), - caption=_('The base part of the URL, without hostname. Just path to home-page of HP.'), - ), + OptionSwitch('HTTP_PROXY', 'General', False, + label=_('Behind proxy'), + caption=_('Headphones works behind proxy, HP will modify url appropriately'), + options=_extend_cb( + OptionDropdown('HTTP_PROXY_HEADER_HOST', 'General', '', initype=str, + label=_('HTTP header with external hostname'), + tooltip=_('The name of HTTP header, which will be used by' + ' CherryPy.tool.proxy.local to determine the external proxy name'), + caption=_('For example, Apache uses "X-Forwarded-Host"'), + items=( + ('', _('Default behaviour')), + ('X-Forwarded-Host', _('Apache [X-Forwarded-Host]')), + ('X-Host', _('Lighttpd [X-Host]')), + ('Host', _('Nginx [Host]')), + ) + ), + ), + ), + OptionString('HTTP_ROOT', 'General', '/', + label=_('HTTP root'), + caption=_('The base part of the URL, without hostname. Just path to home-page of HP.'), + ), )), ]) - opts.extend([ BlockExtension('advanced_forgotten', caption=_("Strange hidden options"), options=_extend_cb( MessageExtension( diff --git a/headphones/webstart.py b/headphones/webstart.py index cc6392216..d31a2feaa 100644 --- a/headphones/webstart.py +++ b/headphones/webstart.py @@ -111,6 +111,13 @@ def initialize(options): }) conf['/api'] = {'tools.auth_basic.on': False} + if options['http_proxy'] and options['http_proxy_header_host']: + logger.info("Work behind proxy enabled, and usage of specific HTTP-header" + " is forced: '%s'", options['http_proxy_header_host']) + conf['/'].update({ + 'tools.proxy.local': options['http_proxy_header_host'], + }) + # Prevent time-outs cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.tree.mount(WebInterface(), str(options['http_root']), config=conf)