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-05-28 15:47:44 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-05-28 15:47:44 +0300
commit84742678227a6153120393366bca6af67f09ac25 (patch)
tree7f4ee43a114f0dcdbf58d88c81356f58fefbd253
parent13e0e3b68135d7af25de12cf6e8f472db030542d (diff)
fix: HTTP: Abort correctly on content overflow
-rw-r--r--nbxmpp/http.py7
-rw-r--r--test/unit/test_http.py24
2 files changed, 29 insertions, 2 deletions
diff --git a/nbxmpp/http.py b/nbxmpp/http.py
index 27cf4fa..9875651 100644
--- a/nbxmpp/http.py
+++ b/nbxmpp/http.py
@@ -373,7 +373,8 @@ class HTTPRequest(GObject.GObject):
return
self._received_size += len(bytes_)
- self._check_content_overflow()
+ if self._check_content_overflow():
+ return
if self._output_stream is None:
self._response_body_data += bytes_
@@ -447,9 +448,11 @@ class HTTPRequest(GObject.GObject):
self.emit('response-progress',
self._received_size / self._response_content_length)
- def _check_content_overflow(self) -> None:
+ def _check_content_overflow(self) -> bool:
if self._received_size > self._response_content_length:
self._finish_read(HTTPRequestError.CONTENT_OVERFLOW)
+ return True
+ return False
def _on_restarted(self, _message: Soup.Message) -> None:
self._log.info('Restarted')
diff --git a/test/unit/test_http.py b/test/unit/test_http.py
index 6ada805..fc22624 100644
--- a/test/unit/test_http.py
+++ b/test/unit/test_http.py
@@ -236,6 +236,30 @@ class HTTP(unittest.TestCase):
self.assertTrue(request4.is_finished())
self.assertTrue(request4.is_complete())
+ def test_content_overflow(self):
+
+ mainloop = GLib.MainLoop()
+
+ session = HTTPSession()
+ request = session.create_request()
+
+
+ def _on_starting(req) -> None:
+ req._received_size = 100000000000
+
+ callback_mock = Mock()
+ request.connect('starting-response-body', _on_starting)
+ request.connect('finished', callback_mock.finished)
+ request.connect('destroy', lambda *args: mainloop.quit())
+ request.send('GET', SMALL_FILE_URL, timeout=10)
+
+ mainloop.run()
+
+ self.assertTrue(request.is_finished())
+ self.assertFalse(request.is_complete())
+ self.assertEqual(request.get_error(), HTTPRequestError.CONTENT_OVERFLOW)
+
+ callback_mock.finished.assert_called()
if __name__ == '__main__':
unittest.main()