Skip to content

Commit c471331

Browse files
MattFlowerMatthew Flower
and
Matthew Flower
authored
fix(integrations): Fix http putrequest when url is None (#1693)
Modifies behavior of putrequest to check for None on real_url prior to using it. Fixes GH-1678 Co-authored-by: Matthew Flower <[email protected]>
1 parent 973b2f6 commit c471331

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

sentry_sdk/integrations/stdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def putrequest(self, method, url, *args, **kwargs):
7171
default_port = self.default_port
7272

7373
real_url = url
74-
if not real_url.startswith(("http://", "https://")):
74+
if real_url is None or not real_url.startswith(("http://", "https://")):
7575
real_url = "%s://%s%s%s" % (
7676
default_port == 443 and "https" or "http",
7777
host,

tests/integrations/stdlib/test_httplib.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
try:
1414
# py2
15-
from httplib import HTTPSConnection
15+
from httplib import HTTPConnection, HTTPSConnection
1616
except ImportError:
1717
# py3
18-
from http.client import HTTPSConnection
18+
from http.client import HTTPConnection, HTTPSConnection
1919

2020
try:
2121
from unittest import mock # python 3.3 and above
@@ -77,6 +77,16 @@ def before_breadcrumb(crumb, hint):
7777
assert sys.getrefcount(response) == 2
7878

7979

80+
def test_empty_realurl(sentry_init, capture_events):
81+
"""
82+
Ensure that after using sentry_sdk.init you can putrequest a
83+
None url.
84+
"""
85+
86+
sentry_init(dsn="")
87+
HTTPConnection("httpbin.org", port=443).putrequest("POST", None)
88+
89+
8090
def test_httplib_misuse(sentry_init, capture_events, request):
8191
"""HTTPConnection.getresponse must be called after every call to
8292
HTTPConnection.request. However, if somebody does not abide by

0 commit comments

Comments
 (0)