Skip to content

Add support for ipv6 address format when parsing url [#648]#649

Merged
beniwohli merged 5 commits into
elastic:masterfrom
mariodev:master
Nov 25, 2019
Merged

Add support for ipv6 address format when parsing url [#648]#649
beniwohli merged 5 commits into
elastic:masterfrom
mariodev:master

Conversation

@mariodev

Copy link
Copy Markdown

What does this pull request do?

The changes are improving get_url_dict util function, to correctly parse ipv6 address.

Why is it important?

Allows to handle request without throwing exception. More details in related issue.

Related issues

closes #648

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for opening the issue and PR @mariodev. I left a comment below :)

Comment thread elasticapm/utils/__init__.py Outdated
def get_url_dict(url):
scheme, netloc, path, params, query, fragment = compat.urlparse.urlparse(url)
if ":" in netloc:
if '[' in netloc and ']' in netloc:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look at ParseResult (the object that urlparse returns). It has properties for hostname and port, which properly support IPv6 URLs since Python 2.7. Only drawback I see is that it'll lowercase IPv6 addresses, but that seems like it isn't a huge problem.

So we would do something like this:

parse_result = compat.urlparse.urlparse(url)

And then use parse_result.hostname, parse_result.port, parse_result.scheme etc. What do you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beniwohli You're right. I refactored the code to use ParseResult. Since the port is returned as integer, I had to add small hack to map into string, so not to introduce any regressions. Thanks for the help.

Comment thread elasticapm/utils/__init__.py Outdated
@beniwohli

Copy link
Copy Markdown
Contributor

jenkins run the tests please

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, thank you so much @mariodev! Just a small little nitpick from our code formatter :)

We have all our linters and code formatters also available as pre-commit hooks if you'd like to send us more pull requests in the future :)

Comment thread elasticapm/utils/__init__.py
@beniwohli beniwohli merged commit 0d2d24e into elastic:master Nov 25, 2019
beniwohli added a commit that referenced this pull request Nov 25, 2019
also, use proper parametrization for test_get_url_dict test cases
beniwohli added a commit that referenced this pull request Nov 25, 2019
also, use proper parametrization for test_get_url_dict test cases
beniwohli pushed a commit that referenced this pull request Nov 25, 2019
* Add support for ipv6 address format when parsing url

* Refactored url parsing to leverage ParseResult object
beniwohli added a commit that referenced this pull request Nov 25, 2019
also, use proper parametrization for test_get_url_dict test cases
@beniwohli

Copy link
Copy Markdown
Contributor

@mariodev I shipped this in version 5.3.2 of the agent. Thanks again for reporting and fixing the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for ipv6 address format

3 participants