Skip to content
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
20 changes: 10 additions & 10 deletions elasticapm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ def is_master_process():


def get_url_dict(url):
scheme, netloc, path, params, query, fragment = compat.urlparse.urlparse(url)
if ":" in netloc:
hostname, port = netloc.split(":")
else:
hostname, port = (netloc, None)
parse_result = compat.urlparse.urlparse(url)

url_dict = {
"full": encoding.keyword_field(url),
"protocol": scheme + ":",
"hostname": encoding.keyword_field(hostname),
"pathname": encoding.keyword_field(path),
"protocol": parse_result.scheme + ":",
"hostname": encoding.keyword_field(parse_result.hostname),
"pathname": encoding.keyword_field(parse_result.path),
}

port = None if parse_result.port is None else str(parse_result.port)

if port:
url_dict["port"] = port
if query:
url_dict["search"] = encoding.keyword_field("?" + query)
if parse_result.query:
url_dict["search"] = encoding.keyword_field("?" + parse_result.query)
return url_dict


Comment thread
beniwohli marked this conversation as resolved.
Expand Down
15 changes: 15 additions & 0 deletions tests/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ def test_get_url_dict():
"search": "?de",
"full": "https://example.com:443/a/b/c?de",
},
"https://[::ffff:a9fe:a9fe]/a/b/c?de": {
"protocol": "https:",
"hostname": "::ffff:a9fe:a9fe",
"pathname": "/a/b/c",
"search": "?de",
"full": "https://[::ffff:a9fe:a9fe]/a/b/c?de",
},
"http://[::ffff:a9fe:a9fe]:80/a/b/c?de": {
"protocol": "http:",
"hostname": "::ffff:a9fe:a9fe",
"port": "80",
"pathname": "/a/b/c",
"search": "?de",
"full": "http://[::ffff:a9fe:a9fe]:80/a/b/c?de",
},
}
for url, expected in data.items():
assert get_url_dict(url) == expected
Expand Down