[tor-commits] [bridgedb/master] Turn HTTP arguments dict from bytes to str.

phw at torproject.org phw at torproject.org
Wed Feb 19 18:26:38 UTC 2020


commit 29c2bd17c43fb5ab541281e7a9d2822fc0045338
Author: Philipp Winter <phw at nymity.ch>
Date:   Thu Jan 30 15:28:06 2020 -0800

    Turn HTTP arguments dict from bytes to str.
---
 bridgedb/distributors/https/server.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index 2d230b9..52a083f 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -974,6 +974,14 @@ class BridgesResource(CustomErrorHandlingResource, CSPResource):
         logging.info("Replying to web request from %s. Parameters were %r"
                      % (ip, request.args))
 
+        # Convert all key/value pairs from bytes to str.
+        str_args = {}
+        for arg, values in request.args.items():
+            arg = arg if isinstance(arg, str) else arg.decode("utf-8")
+            values = [value.decode("utf-8") if isinstance(value, bytes) else value for value in values]
+            str_args[arg] = values
+        request.args = str_args
+
         if ip:
             bridgeRequest = HTTPSBridgeRequest()
             bridgeRequest.client = ip





More information about the tor-commits mailing list