Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-01-02 02:03:44 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-01-02 02:06:47 +0300
commit964fa149cf0502bdb43b561e458ae431414eae42 (patch)
tree5c6c42dded7be42a968d16cfbecf451e7948eb85
parentc3b9bd4e7ed989ed1bfe78620748fbe97aebb129 (diff)
refactor: Don’t cancel when content-length is not available
In this case we default to content-length = 0
-rw-r--r--nbxmpp/const.py11
-rw-r--r--nbxmpp/http.py23
2 files changed, 10 insertions, 24 deletions
diff --git a/nbxmpp/const.py b/nbxmpp/const.py
index 932a98f..b3fd201 100644
--- a/nbxmpp/const.py
+++ b/nbxmpp/const.py
@@ -456,12 +456,11 @@ class Mode(IntEnum):
class HTTPRequestError(IntEnum):
UNKNOWN = 0
- MISSING_CONTENT_LENGTH = 1
- INCOMPLETE = 2
- STATUS_NOT_OK = 3
- CANCELLED = 4
- CONTENT_OVERFLOW = 5
- TIMEOUT = 6
+ INCOMPLETE = 1
+ STATUS_NOT_OK = 2
+ CANCELLED = 3
+ CONTENT_OVERFLOW = 4
+ TIMEOUT = 5
MOODS = [
diff --git a/nbxmpp/http.py b/nbxmpp/http.py
index d0f8a07..a2dd84b 100644
--- a/nbxmpp/http.py
+++ b/nbxmpp/http.py
@@ -30,7 +30,6 @@ from gi.repository import GLib
from gi.repository import GObject
import nbxmpp
-from .util import convert_soup_encoding
from .const import HTTPRequestError
@@ -109,7 +108,6 @@ class HTTPRequest(GObject.GObject):
self._is_complete = False
self._timeout_reached = False
self._timeout_id = None
- self._no_content_length_set = False
self._response_body_file: Optional[Gio.File] = None
self._response_body_data = b''
@@ -315,10 +313,7 @@ class HTTPRequest(GObject.GObject):
except GLib.Error as error:
quark = GLib.quark_try_string('g-io-error-quark')
if error.matches(quark, Gio.IOErrorEnum.CANCELLED):
- if self._no_content_length_set:
- self._set_failed(HTTPRequestError.MISSING_CONTENT_LENGTH)
- else:
- self._set_failed(HTTPRequestError.CANCELLED)
+ self._set_failed(HTTPRequestError.CANCELLED)
return
self._log.error(error)
@@ -407,26 +402,18 @@ class HTTPRequest(GObject.GObject):
_params: GLib.HashTable,
) -> None:
- if self._message.get_status() not in (Soup.Status.OK,
- Soup.Status.CREATED):
- return
+ # Signal is only raised when there is content in the response
headers = message.get_response_headers()
- encoding = headers.get_encoding()
- if Soup.Encoding.CONTENT_LENGTH not in convert_soup_encoding(encoding):
- self._log.warning('No content-length in response')
- self._no_content_length_set = True
- self.cancel()
- return
self._response_content_length = headers.get_content_length()
if content_type is None:
# According to the docs, content_type is None when the sniffer
# decides to trust the content-type sent by the server.
- self._response_content_type = headers.get_content_type()
- else:
- self._response_content_type = content_type
+ content_type, _ = headers.get_content_type()
+
+ self._response_content_type = content_type or ''
self._log.info('Sniffed: content-type: %s, content-length: %s',
self._response_content_type,