diff --git a/AUTHORS.md b/AUTHORS.md index 1112319a7..b20287131 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -174,6 +174,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/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/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 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 () {}; diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 6f5f333ad..3ab1afed7 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -6110,7 +6110,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*))+" )