[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Accept all 2xx response codes



commit 8d1effca8fa37062ada130cfe50955ff9bb0359b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Aug 13 17:32:10 2020 -0700

    Accept all 2xx response codes
    
    Tor uses a similar response code scheme as HTTP (2xx = ok, 4xx = error,
    5xx = fatal). Most successful responses are 250, but better to accept
    all 2xx codes.
---
 stem/response/__init__.py     | 6 +++---
 test/unit/response/getconf.py | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 5749fbcb..b4c7aed5 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -235,13 +235,13 @@ class ControlMessage(object):
 
   def is_ok(self) -> bool:
     """
-    Checks if any of our lines have a 250, 251 or 252 response.
+    Checks if any of our lines have a 2xx response.
 
-    :returns: **True** if any lines have a 250, 251 or 252 response code, **False** otherwise
+    :returns: **True** if any lines have a 2xx response code, **False** otherwise
     """
 
     for code, _, _ in self._parsed_content:
-      if code in ['250', '251', '252']:
+      if code.isdigit() and (200 <= int(code) < 300):
         return True
 
     return False
diff --git a/test/unit/response/getconf.py b/test/unit/response/getconf.py
index c9765fcf..9d1b1b96 100644
--- a/test/unit/response/getconf.py
+++ b/test/unit/response/getconf.py
@@ -31,7 +31,7 @@ UNRECOGNIZED_KEY_RESPONSE = '''552-Unrecognized configuration key "brickroad"
 
 INVALID_RESPONSE = """\
 123-FOO
-232 BAR"""
+532 BAR"""
 
 
 class TestGetConfResponse(unittest.TestCase):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits