Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
964fa149 by Philipp Hörist at 2023-01-02T00:06:47+01:00
refactor: Don’t cancel when content-length is not available
In this case we default to content-length = 0
- - - - -
2 changed files:
- nbxmpp/const.py
- nbxmpp/http.py
Changes:
=====================================
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 = [
=====================================
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,
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/964fa149cf0502bdb43b561e458ae431414eae42
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/964fa149cf0502bdb43b561e458ae431414eae42
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits