From a49bc9ca755b61a9f429d4fa1aca40bd9ea66d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Jul 2016 19:02:12 +0200 Subject: [PATCH 1/2] Fixed wrong placeholders in format string for exception --- src/octoprint/filemanager/storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index bbbc51aa..f3d4dd5f 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -398,7 +398,7 @@ class LocalFileStorage(StorageInterface): folder_path = os.path.join(path, name) if os.path.exists(folder_path): if not ignore_existing: - raise RuntimeError("{sanitized_foldername} does already exist in {virtual_path}".format(**locals())) + raise RuntimeError("{name} does already exist in {path}".format(**locals())) else: os.mkdir(folder_path) @@ -415,7 +415,7 @@ class LocalFileStorage(StorageInterface): if ".metadata.yaml" in contents: contents.remove(".metadata.yaml") if contents and not recursive: - raise RuntimeError("{sanitized_foldername} in {virtual_path} is not empty".format(**locals())) + raise RuntimeError("{name} in {path} is not empty".format(**locals())) import shutil shutil.rmtree(folder_path) From 6018bf84281ac4314a0d080f031147bc1eb1d1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Jul 2016 19:28:20 +0200 Subject: [PATCH 2/2] Fix overeager preemptive caching, even on broken protocols --- src/octoprint/server/__init__.py | 6 ++++++ src/octoprint/server/util/flask.py | 10 +++++++--- src/octoprint/server/views.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 7fd0eb70..0b2e1206 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -793,6 +793,12 @@ class Server(object): additional_request_data = kwargs.get("_additional_request_data", dict()) kwargs = dict((k, v) for k, v in kwargs.items() if not k.startswith("_") and not k == "plugin") kwargs.update(additional_request_data) + + base_url = kwargs.get("base_url", "") + if not (base_url.startswith("http://") or base_url.startswith("https://")): + self._logger.info("Skipping preemptive cache entry with base url {}, neither http:// nor https:// and possibly broken".format(base_url)) + continue + try: if plugin: self._logger.info("Preemptively caching {} (plugin {}) for {!r}".format(route, plugin, kwargs)) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 68f25703..4f6b3dbe 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -488,6 +488,12 @@ class PreemptiveCache(object): return matched, unmatched with self._lock: + if not self._log_access: + self._logger.debug( + "Not updating timestamp and counter for {} and {!r}, currently flagged as disabled".format(root, + data)) + return + cache_data = self.get_all_data() if not root in cache_data: @@ -509,12 +515,10 @@ class PreemptiveCache(object): to_persist["_timestamp"] = time.time() to_persist["_count"] = 1 self._logger.info("Adding entry for {} and {!r}".format(root, to_persist)) - elif self._log_access: + else: to_persist["_timestamp"] = time.time() to_persist["_count"] = to_persist.get("_count", 0) + 1 self._logger.debug("Updating timestamp and counter for {} and {!r}".format(root, data)) - else: - self._logger.debug("Not updating timestamp and counter for {} and {!r}, currently flagged as disabled".format(root, data)) self.set_data(root, [to_persist] + other) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 3b74bb74..6140eb4c 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -32,7 +32,7 @@ _valid_div_re = re.compile("[a-zA-Z_-]+") @app.route("/") @util.flask.preemptively_cached(cache=preemptiveCache, data=lambda: dict(path=request.path, base_url=request.url_root, query_string="l10n={}".format(g.locale.language) if g.locale else "en"), - unless=lambda: request.url_root in settings().get(["server", "preemptiveCache", "exceptions"])) + unless=lambda: request.url_root in settings().get(["server", "preemptiveCache", "exceptions"]) or not (request.url_root.startswith("http://") or request.url_root.startswith("https://"))) @util.flask.conditional(lambda: _check_etag_and_lastmodified_for_index(), NOT_MODIFIED) @util.flask.cached(timeout=-1, refreshif=lambda cached: _validate_cache_for_index(cached),