From c38c93bff12ea1192c96db27d4115b1935f7a9b3 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Thu, 30 Sep 2021 10:40:04 +0800 Subject: [PATCH] Ports: Patch Python's http.client due to unimplemented socket option This problem has been reported on https://bugs.python.org/issue45328 and a fix has been provided, potential review and merge are pending. --- Ports/python3/patches/ReadMe.md | 4 ++++ Ports/python3/patches/http-client.patch | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Ports/python3/patches/http-client.patch diff --git a/Ports/python3/patches/ReadMe.md b/Ports/python3/patches/ReadMe.md index c068b1e753..c862a201e9 100644 --- a/Ports/python3/patches/ReadMe.md +++ b/Ports/python3/patches/ReadMe.md @@ -16,6 +16,10 @@ Enforce UTF-8 as encoding by defining `_Py_FORCE_UTF8_LOCALE`. As usual, make the `configure` script recognize Serenity. Also set `MACHDEP` (which is used for `sys.platform`) to a version-less `serenityos`, even when not cross-compiling. +## `http-client.patch` + +Allows HTTPConnection to work without the TCP_NODELAY socket option, as this is not supported by Serenity. + ## `tweak-setup-py.patch` Make some tweaks to Python's `setup.py` files: diff --git a/Ports/python3/patches/http-client.patch b/Ports/python3/patches/http-client.patch new file mode 100644 index 0000000000..baefdb8453 --- /dev/null +++ b/Ports/python3/patches/http-client.patch @@ -0,0 +1,24 @@ +--- Python-3.10/Lib/http/client.py 2021-09-07 21:18:28.000000000 +0800 ++++ Python-3.10/Lib/http/client.py 2021-09-30 10:22:31.513921004 +0800 +@@ -70,6 +70,7 @@ + + import email.parser + import email.message ++import errno + import http + import io + import re +@@ -939,7 +940,12 @@ + sys.audit("http.client.connect", self, self.host, self.port) + self.sock = self._create_connection( + (self.host,self.port), self.timeout, self.source_address) +- self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) ++ # Might fail in OSs that don't implement TCP_NODELAY ++ try: ++ self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) ++ except OSError as e: ++ if e.errno != errno.ENOPROTOOPT: ++ raise + + if self._tunnel_host: + self._tunnel()