From 474c7922338929b499ceef0c04ccea83e530c229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Dec 2023 15:20:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20double=20response=20on=20P?= =?UTF-8?q?OST/PUT/etc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not setting the _finished flag to True caused the UploadStorage- FallbackHandler to generate an additional empty text/html response for every POST/PUT/etc request. If that arrived inside a keep-alive connection followed by additional requests, it caused the browser to consider the text/html response to be the response to the follow-up request, causing all kinds of mayhem. --- src/octoprint/server/util/tornado.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 3ab3bf621..8b5539a74 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -311,6 +311,7 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin, CorsSupport else: self._fallback(self.request, b"") self._finished = True + self.on_finish() def data_received(self, chunk): """ @@ -591,10 +592,12 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin, CorsSupport result = self._fallback(self.request, body) if result is not None: await result - # self._headers_written = True finally: - # make sure the temporary files are removed again - self._cleanup_files() + self._finished = True + self.on_finish() + + def on_finish(self): + self._cleanup_files() def _cleanup_files(self): """