From 292856e1bd447e390b32cc232297ba1434500e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 29 Dec 2014 20:45:54 +0100 Subject: [PATCH 1/3] Fixed relative URL to sockjs endpoint, wasn't yet using the proper base url --- CHANGELOG.md | 3 +++ src/octoprint/templates/index.jinja2 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e12f3ae8..d5db9e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [#634](https://github.com/foosel/OctoPrint/pull/634) - Fixed missing `branch` fields in version dicts generated by versioneer * [IRC] Don't hiccup on slic3r filament_diameter comments generated for multi extruder setups +* [ML] Fixed relative URL to sockjs endpoint, wasn't yet using the proper base url * Small fixes for timelapse creation: - [#344](https://github.com/foosel/OctoPrint/issues/344) - Made timelapses capable of coping with missing captures in between by decrementing the image counter again if there was an error fetching the latest image from the snapshot URL (backport of [1a7a468](https://github.com/foosel/OctoPrint/commit/1a7a468eb65fdf2a13b4c7a7723280e822c9c34b) @@ -36,6 +37,8 @@ * [#604](https://github.com/foosel/OctoPrint/issues/604) - Properly initialize settings basedir on server startup * [IRC] Also allow downloading .g files via Tornado +([Commits](https://github.com/foosel/OctoPrint/compare/1.1.0...1.1.1)) + ## 1.1.0 (2014-09-03) ### New Features diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 28d5b4f3..fa0d72ec 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -37,7 +37,7 @@ var CONFIG_GCODE_SIZE_THRESHOLD = {{ gcodeThreshold }}; var CONFIG_GCODE_MOBILE_SIZE_THRESHOLD = {{ gcodeMobileThreshold }}; - var SOCKJS_URI = window.location.protocol.slice(0, -1) + "://" + (window.document ? window.document.domain : window.location.hostname) + ":" + window.location.port + "/sockjs"; + var SOCKJS_URI = "{{ url_for('index') }}" + "sockjs"; var SOCKJS_DEBUG = {% if debug -%} true; {% else %} false; {%- endif %} From e3383fe4c1b54b15318d618a831e0b93642a8651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 29 Dec 2014 20:48:33 +0100 Subject: [PATCH 2/3] Generated URLs now take X-Forwarded-Host header sent by proxies into account for included host and port --- CHANGELOG.md | 1 + src/octoprint/server/util.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5db9e5e..22c8a8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ by versioneer * [IRC] Don't hiccup on slic3r filament_diameter comments generated for multi extruder setups * [ML] Fixed relative URL to sockjs endpoint, wasn't yet using the proper base url +* [unreported] Generated URLs now take X-Forwarded-Host header sent by proxies into account for included host and port * Small fixes for timelapse creation: - [#344](https://github.com/foosel/OctoPrint/issues/344) - Made timelapses capable of coping with missing captures in between by decrementing the image counter again if there was an error fetching the latest image from the snapshot URL (backport of [1a7a468](https://github.com/foosel/OctoPrint/commit/1a7a468eb65fdf2a13b4c7a7723280e822c9c34b) diff --git a/src/octoprint/server/util.py b/src/octoprint/server/util.py index 71149686..4e03d49a 100644 --- a/src/octoprint/server/util.py +++ b/src/octoprint/server/util.py @@ -373,6 +373,14 @@ class ReverseProxied(object): if scheme: environ['wsgi.url_scheme'] = scheme + + host = environ.get('HTTP_X_FORWARDED_HOST', '') + if not host: + host = settings().get(["server", "host"]) + + if host: + environ['HTTP_HOST'] = host + return self.app(environ, start_response) From 87ddcac2fce893ef9c9d749c50623b98fc354bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 30 Dec 2014 10:20:50 +0100 Subject: [PATCH 3/3] Don't user server.host but server.forwardedHost as fallback for generated external URLs Closes #698 --- CHANGELOG.md | 8 +++++--- src/octoprint/server/util.py | 2 +- src/octoprint/settings.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c8a8ab..87e44208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ * [#634](https://github.com/foosel/OctoPrint/pull/634) - Fixed missing `branch` fields in version dicts generated by versioneer -* [IRC] Don't hiccup on slic3r filament_diameter comments generated for multi extruder setups -* [ML] Fixed relative URL to sockjs endpoint, wasn't yet using the proper base url -* [unreported] Generated URLs now take X-Forwarded-Host header sent by proxies into account for included host and port +* [IRC] - Don't hiccup on slic3r filament_diameter comments generated for multi extruder setups +* [ML] - Fixed relative URL to sockjs endpoint, wasn't yet using the proper base url +* [unreported] & [#698](https://github.com/foosel/OctoPrint/issues/698) - Generated URLs now take X-Forwarded-Host header + sent by proxies into account for included host and port, also fixed [#698](https://github.com/foosel/OctoPrint/issues/698) + introduced by this * Small fixes for timelapse creation: - [#344](https://github.com/foosel/OctoPrint/issues/344) - Made timelapses capable of coping with missing captures in between by decrementing the image counter again if there was an error fetching the latest image from the snapshot URL (backport of [1a7a468](https://github.com/foosel/OctoPrint/commit/1a7a468eb65fdf2a13b4c7a7723280e822c9c34b) diff --git a/src/octoprint/server/util.py b/src/octoprint/server/util.py index 4e03d49a..de782d26 100644 --- a/src/octoprint/server/util.py +++ b/src/octoprint/server/util.py @@ -376,7 +376,7 @@ class ReverseProxied(object): host = environ.get('HTTP_X_FORWARDED_HOST', '') if not host: - host = settings().get(["server", "host"]) + host = settings().get(["server", "forwardedHost"]) if host: environ['HTTP_HOST'] = host diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 0f70641f..259edaac 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -43,7 +43,8 @@ default_settings = { "firstRun": True, "secretKey": None, "baseUrl": "", - "scheme": "" + "scheme": "", + "forwardedHost": "" }, "webcam": { "stream": None,