Skip to content

Commit

Permalink
fix(integrations): Fix http putrequest when url is None (#1693)
Browse files Browse the repository at this point in the history
Modifies behavior of putrequest to check for None on real_url prior to using it.

Fixes GH-1678

Co-authored-by: Matthew Flower <matt.flower@january.com>
  • Loading branch information
MattFlower and Matthew Flower committed Oct 20, 2022
1 parent 973b2f6 commit c471331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def putrequest(self, method, url, *args, **kwargs):
default_port = self.default_port

real_url = url
if not real_url.startswith(("http://", "https://")):
if real_url is None or not real_url.startswith(("http://", "https://")):
real_url = "%s://%s%s%s" % (
default_port == 443 and "https" or "http",
host,
Expand Down
14 changes: 12 additions & 2 deletions tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

try:
# py2
from httplib import HTTPSConnection
from httplib import HTTPConnection, HTTPSConnection
except ImportError:
# py3
from http.client import HTTPSConnection
from http.client import HTTPConnection, HTTPSConnection

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


def test_empty_realurl(sentry_init, capture_events):
"""
Ensure that after using sentry_sdk.init you can putrequest a
None url.
"""

sentry_init(dsn="")
HTTPConnection("httpbin.org", port=443).putrequest("POST", None)


def test_httplib_misuse(sentry_init, capture_events, request):
"""HTTPConnection.getresponse must be called after every call to
HTTPConnection.request. However, if somebody does not abide by
Expand Down

0 comments on commit c471331

Please sign in to comment.