Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsgi: Fix port 80 always appended in http.host. #173

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ def _add_request_attributes(span, environ):
if not host:
host = environ["SERVER_NAME"]
port = environ["SERVER_PORT"]
scheme = environ["wsgi.url_scheme"]
if (
port != "80"
and environ["wsgi.url_scheme"] == "http"
or port != "443"
scheme == "http"
and port != "80"
or scheme == "https"
and port != "443"
):
host += ":" + port

Expand Down
16 changes: 13 additions & 3 deletions ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ def validate_url(self, expected_url):
self.assertIn("http.url", attrs)
self.assertEqual(attrs["http.url"], expected_url)
self.assertIn("http.host", attrs)
self.assertEqual(
attrs["http.host"], urlparse(attrs["http.url"]).netloc
)
self.assertEqual(attrs["http.host"], urlparse(expected_url).netloc)

def test_request_attributes_with_partial_raw_uri(self):
self.environ["RAW_URI"] = "/#top"
Expand All @@ -231,6 +229,18 @@ def test_https_uri_port(self):
self.environ["SERVER_PORT"] = "80"
self.validate_url("https://127.0.0.1:80/")

def test_http_uri_port(self):
del self.environ["HTTP_HOST"]
self.environ["SERVER_PORT"] = "80"
self.environ["wsgi.url_scheme"] = "http"
self.validate_url("http://127.0.0.1/")

self.environ["SERVER_PORT"] = "8080"
self.validate_url("http://127.0.0.1:8080/")

self.environ["SERVER_PORT"] = "443"
self.validate_url("http://127.0.0.1:443/")

def test_request_attributes_with_nonstandard_port_and_no_host(self):
del self.environ["HTTP_HOST"]
self.environ["SERVER_PORT"] = "8080"
Expand Down