Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 5afb2b4a by Philipp Hörist at 2023-05-21T09:37:41+02:00 cfix: HTTP: Use cancel() to abort download in got-body-data callback
Fixes #144
- - - - -
2 changed files:
- nbxmpp/const.py - nbxmpp/http.py
Changes:
===================================== nbxmpp/const.py ===================================== @@ -462,6 +462,9 @@ class HTTPRequestError(IntEnum): CONTENT_OVERFLOW = 4 TIMEOUT = 5
+ def __str__(self) -> str: + return self.name +
MOODS = [ 'afraid',
===================================== nbxmpp/http.py ===================================== @@ -305,6 +305,8 @@ class HTTPRequest(GObject.GObject):
def _on_timeout(self) -> None: self._timeout_reached = True + self._timeout_id = None + self._set_error(HTTPRequestError.TIMEOUT) self.cancel()
def _on_response(self, @@ -312,9 +314,6 @@ class HTTPRequest(GObject.GObject): result: Gio.AsyncResult ) -> None:
- if self._is_finished: - return - self._log.info('Request response received') try: self._input_stream = session.send_finish(result) @@ -351,9 +350,6 @@ class HTTPRequest(GObject.GObject): input_stream: Gio.InputStream, result: Gio.AsyncResult) -> None:
- if self._is_finished: - return - try: data = input_stream.read_bytes_finish(result) except GLib.Error as error: @@ -463,7 +459,8 @@ class HTTPRequest(GObject.GObject):
def _check_content_overflow(self) -> None: if self._received_size > self._response_content_length: - self._finish_read(HTTPRequestError.CONTENT_OVERFLOW) + self._set_error(HTTPRequestError.CONTENT_OVERFLOW) + self.cancel()
def _on_restarted(self, _message: Soup.Message) -> None: self._log.info('Restarted') @@ -503,14 +500,16 @@ class HTTPRequest(GObject.GObject):
self._set_complete()
+ def _set_error(self, error: HTTPRequestError) -> None: + self._log.info('Set Error: %s', error) + self._error = error + def _set_failed(self, error: HTTPRequestError) -> None: self._log.info('Set Failed: %s', error) self._is_finished = True - if self._timeout_reached: - self._timeout_id = None - self._error = HTTPRequestError.TIMEOUT - else: - self._error = error + + if self._error is None: + self._set_error(error)
self._close_all_streams() self.emit('finished')
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/5afb2b4a14e62b3b5f9b0d1c2...