aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_http_check_ratelimited.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-10-15 00:27:33 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2022-10-15 00:27:33 +0200
commit3aa2c79d80e17ed1ca02e7698e68218d57bfb47b (patch)
tree1a49e5c7046d070dacdd9962552dbba5d38b016a /_pytest/test_http_check_ratelimited.py
parentf7a6193e57dd116ad20d531ccdab22d48959656e (diff)
downloadwee-slack-3aa2c79d80e17ed1ca02e7698e68218d57bfb47b.tar.gz
Support receiving multiple header blocks in http responses
One user experiences receiving a "HTTP/1.1 200 Connection established" header block before a "HTTP/2 200" header block with the headers. I'm not sure why specifically this happens, but I know a similar response will happen if redirects are followed. This wasn't supported by the http_check_ratelimited function which splits the header from the body. It now splits out all the header blocks from the body and uses the status and headers from the last one.
Diffstat (limited to '_pytest/test_http_check_ratelimited.py')
-rw-r--r--_pytest/test_http_check_ratelimited.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/_pytest/test_http_check_ratelimited.py b/_pytest/test_http_check_ratelimited.py
new file mode 100644
index 0000000..948f247
--- /dev/null
+++ b/_pytest/test_http_check_ratelimited.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function, unicode_literals
+from textwrap import dedent
+
+from wee_slack import SlackRequest
+
+
+def test_http_check_ratelimited_supports_multiple_headers(realish_eventrouter):
+ response = (
+ dedent(
+ """
+ HTTP/1.1 200 Connection established
+
+ HTTP/2 200
+ content-type: application/json; charset=utf-8
+
+ {"ok": true}
+ """
+ )
+ .strip()
+ .replace("\n", "\r\n")
+ )
+
+ request_metadata = SlackRequest(None, "", token="xoxp-1")
+ body, error = realish_eventrouter.http_check_ratelimited(request_metadata, response)
+ assert body == '{"ok": true}'
+ assert error == ""
+
+
+def test_http_check_ratelimited_return_error_when_ratelimited(realish_eventrouter):
+ response = (
+ dedent(
+ """
+ HTTP/2 429
+ content-type: application/json; charset=utf-8
+ retry-after: 10
+
+ {"ok": false, "error": "ratelimited"}
+ """
+ )
+ .strip()
+ .replace("\n", "\r\n")
+ )
+
+ request_metadata = SlackRequest(None, "", token="xoxp-1")
+ body, error = realish_eventrouter.http_check_ratelimited(request_metadata, response)
+ assert body == ""
+ assert error == "ratelimited"