Fixed issue with empty proxies being passed
authorEric Hansen <ehansen@securityfor.us>
Tue, 11 Sep 2012 19:40:16 +0000 (15:40 -0400)
committerEric Hansen <ehansen@securityfor.us>
Tue, 11 Sep 2012 19:40:16 +0000 (15:40 -0400)
requests/models.py
tests/test_proxies.py [new file with mode: 0644]

index 031efee359586cc4fb3e635c102899ce1fa1a4f6..0ef30251b68b5396aa6d36f1ab8a97b0e09e63e1 100644 (file)
@@ -111,6 +111,10 @@ class Request(object):
         # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})
         self.proxies = dict(proxies or [])
 
+        for proxy_type,uri_ref in self.proxies.items():
+            if not uri_ref:
+                del self.proxies[proxy_type]
+
         # If no proxies are given, allow configuration by environment variables
         # HTTP_PROXY and HTTPS_PROXY.
         if not self.proxies and self.config.get('trust_env'):
diff --git a/tests/test_proxies.py b/tests/test_proxies.py
new file mode 100644 (file)
index 0000000..8ab124b
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys, os, unittest
+
+# Path hack.
+sys.path.insert(0, os.path.abspath('..'))
+import requests
+
+
+class HTTPSProxyTest(unittest.TestCase):
+    """Smoke test for https functionality."""
+
+    smoke_url = "https://github.com"
+
+    def test_empty_https_proxy(self):
+        proxy = {"https" : "" }
+        result = requests.get(self.smoke_url, verify=False, proxies = proxy)
+        self.assertEqual(result.status_code, 200)
+
+    def test_empty_http_proxy(self):
+        proxy = {"http" : "" }
+        result = requests.get(self.smoke_url, proxies = proxy)
+        self.assertEqual(result.status_code, 200)
+
+if __name__ == '__main__':
+    unittest.main()