Skip to content

Commit 29da0a4

Browse files
committed
ref(wsgi): Delete custom _werkzeug and use new Werkzeug version
Fixes: GH-3516
1 parent eee4cac commit 29da0a4

File tree

2 files changed

+13
-101
lines changed

2 files changed

+13
-101
lines changed

sentry_sdk/_werkzeug.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

sentry_sdk/integrations/wsgi.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from functools import partial
33

44
import sentry_sdk
5-
from sentry_sdk._werkzeug import get_host, _get_headers
5+
from werkzeug.datastructures import EnvironHeaders
6+
from werkzeug.wsgi import get_host
67
from sentry_sdk.api import continue_trace
78
from sentry_sdk.consts import OP
89
from sentry_sdk.scope import should_send_default_pii
@@ -62,9 +63,18 @@ def get_request_url(environ, use_x_forwarded_for=False):
6263
path_info = environ.get("PATH_INFO", "").lstrip("/")
6364
path = f"{script_name}/{path_info}"
6465

66+
if use_x_forwarded_for and "HTTP_X_FORWARDED_HOST" in environ:
67+
host = environ["HTTP_X_FORWARDED_HOST"]
68+
if environ.get("wsgi.url_scheme") == "http" and host.endswith(":80"):
69+
host = host[:-3]
70+
elif environ.get("wsgi.url_scheme") == "https" and host.endswith(":443"):
71+
host = host[:-4]
72+
else:
73+
host = get_host(environ)
74+
6575
return "%s://%s/%s" % (
6676
environ.get("wsgi.url_scheme"),
67-
get_host(environ, use_x_forwarded_for),
77+
host,
6878
wsgi_decoding_dance(path).lstrip("/"),
6979
)
7080

@@ -286,7 +296,7 @@ def _make_wsgi_event_processor(environ, use_x_forwarded_for):
286296
query_string = environ.get("QUERY_STRING")
287297
method = environ.get("REQUEST_METHOD")
288298
env = dict(_get_environ(environ))
289-
headers = _filter_headers(dict(_get_headers(environ)))
299+
headers = _filter_headers(dict(EnvironHeaders(environ)))
290300

291301
def event_processor(event, hint):
292302
# type: (Event, Dict[str, Any]) -> Event

0 commit comments

Comments
 (0)