From 7f3bd32d8842dfe54088180fd439098560feddde Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:15:20 +0000 Subject: [PATCH 1/3] :sparkles: Add `removeMessage` to OctoPrint socket (#4708) --- docs/jsclientlib/socket.rst | 17 +++++++++++++++++ src/octoprint/static/js/app/client/socket.js | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index fc4223546..aaf5a5e6a 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -60,6 +60,23 @@ :param string message: The type of message for which to register :param function handler: The handler function +.. js:function:: OctoPrintClient.socker.removeMessage(message, handler) + + Removes the ``handler`` for messages of type ``message``. + + .. code-block:: javascript + + const handler = (message) => { + // do something with the message object + }; + + OctoPrint.socket.onMessage("*", handler); + // Use the same reference to the handler function to remove it again + OctoPrint.socket.removeMessage("*", handler); + + :param string message: The type of message for which to remove the handler + :param function handler: The handler function + .. js:function:: OctoPrintClient.socket.sendMessage(type, payload) Sends a message of type ``type`` with the provided ``payload`` to the server. diff --git a/src/octoprint/static/js/app/client/socket.js b/src/octoprint/static/js/app/client/socket.js index 8408e5606..cfa73311f 100644 --- a/src/octoprint/static/js/app/client/socket.js +++ b/src/octoprint/static/js/app/client/socket.js @@ -220,6 +220,18 @@ return this; }; + OctoPrintSocketClient.prototype.removeMessage = function (message, handler) { + if (!this.registeredHandlers.hasOwnProperty(message)) { + // No handlers registered, do nothing + return; + } + + const index = OctoPrint.socket.registeredHandlers[message].indexOf(handler); + if (index > -1) { + OctoPrint.socket.registeredHandlers[message].splice(index, 1); + } + }; + OctoPrintSocketClient.prototype.onReconnectAttempt = function (trial) {}; OctoPrintSocketClient.prototype.onReconnectFailed = function () {}; OctoPrintSocketClient.prototype.onConnected = function () {}; From f64ed8aecf57d064adfae928872601aa9fbd792e Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:16:37 +0000 Subject: [PATCH 2/3] :bug: Support the R parameter in temperature offsets (#4696) Closes #4695 M109 R200 would be a valid temperature command --- src/octoprint/util/comm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index c684cc582..44f00b56f 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -6113,7 +6113,7 @@ class SendQueue(PrependableQueue): _temp_command_regex = re.compile( - r"^M(?P104|109|140|190)(\s+T(?P\d+)|\s+S(?P[-+]?\d*\.?\d*))+" + r"^M(?P104|109|140|190)(\s+T(?P\d+)|\s+[SR](?P[-+]?\d*\.?\d*))+" ) From 5443b3fe270d5bc2de7ef09a20a5555ae793c196 Mon Sep 17 00:00:00 2001 From: Moiz Rasheed Date: Mon, 16 Jan 2023 11:59:13 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20Remove=20Transfer-Encoding?= =?UTF-8?q?=20header=20so=20input=20is=20interpreted=20correctly=20by=20fl?= =?UTF-8?q?ask=20(#4689)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AUTHORS.md | 1 + src/octoprint/server/util/tornado.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index ef24edf84..b9e3aaea1 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -173,6 +173,7 @@ date of first contribution): * [Arkadiusz Miƛkiewicz](https://github.com/arekm) * ["tempodat"](https://github.com/tempodat) * [Frederik Kemner](https://github.com/040medien) + * [Moiz Rasheed](https://github.com/msrasheed) * [Scott Martin](https://github.com/smartin015) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 1882a735b..0957fb577 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -795,6 +795,14 @@ class WsgiInputContainer: environ["CONTENT_TYPE"] = request.headers.pop("Content-Type") if "Content-Length" in request.headers: environ["CONTENT_LENGTH"] = request.headers.pop("Content-Length") + + # remove transfer encoding header if chunked, otherwise flask wsgi entrypoint makes input empty + if ( + "Transfer-Encoding" in request.headers + and request.headers.get("Transfer-Encoding") == "chunked" + ): + request.headers.pop("Transfer-Encoding") + for key, value in request.headers.items(): environ["HTTP_" + key.replace("-", "_").upper()] = value return environ