Merge pull request #866 from JackDandy/feature/ChangeWebStartup

Change webserver startup to correctly use xheaders in reverse proxy o…
This commit is contained in:
JackDandy 2017-02-01 03:19:38 +00:00 committed by GitHub
commit df1f23480c
2 changed files with 10 additions and 14 deletions

View file

@ -7,6 +7,7 @@
* Update isotope library 2.2.2 to 3.0.1
* Add lazyload package 3.0.0 (2e318b1)
* Change improve add show search results by comparing search term to an additional unidecoded result set
* Change webserver startup to correctly use xheaders in reverse proxy or load balance set-ups
[develop changelog]

View file

@ -19,6 +19,7 @@ class WebServer(threading.Thread):
self.alive = True
self.name = 'TORNADO'
self.io_loop = io_loop or IOLoop.current()
self.server = None
self.options = options
self.options.setdefault('port', 8081)
@ -31,8 +32,7 @@ class WebServer(threading.Thread):
assert 'data_root' in self.options
# web root
self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/')) if self.options[
'web_root'] else ''
self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/')) if self.options['web_root'] else ''
# tornado setup
self.enable_https = self.options['enable_https']
@ -58,10 +58,8 @@ class WebServer(threading.Thread):
debug=True,
autoreload=False,
gzip=True,
xheaders=sickbeard.HANDLE_REVERSE_PROXY,
cookie_secret=sickbeard.COOKIE_SECRET,
login_url='%s/login/' % self.options['web_root']
)
login_url='%s/login/' % self.options['web_root'])
# Main Handler
self.app.add_handlers('.*$', [
@ -126,19 +124,16 @@ class WebServer(threading.Thread):
])
def run(self):
if self.enable_https:
protocol = 'https'
self.server = HTTPServer(self.app, ssl_options={'certfile': self.https_cert, 'keyfile': self.https_key})
else:
protocol = 'http'
self.server = HTTPServer(self.app)
protocol, ssl_options = (('http', None),
('https', {'certfile': self.https_cert, 'keyfile': self.https_key}))[self.enable_https]
logger.log(u'Starting SickGear on ' + protocol + '://' + str(self.options['host']) + ':' + str(
self.options['port']) + '/')
try:
self.server.listen(self.options['port'], self.options['host'])
except:
self.server = self.app.listen(self.options['port'], self.options['host'], ssl_options=ssl_options,
xheaders=sickbeard.HANDLE_REVERSE_PROXY, protocol=protocol)
except (StandardError, Exception):
etype, evalue, etb = sys.exc_info()
logger.log(
'Could not start webserver on %s. Excpeption: %s, Error: %s' % (self.options['port'], etype, evalue),
@ -154,4 +149,4 @@ class WebServer(threading.Thread):
def shutDown(self):
self.alive = False
self.io_loop.stop()
self.io_loop.stop()