Skip to content

Fix handling of bolt URL with port 80 #364

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

Merged
merged 2 commits into from
Apr 30, 2018
Merged

Conversation

lutovich
Copy link
Contributor

URLs are currently parsed in two places in the driver. First is before driver creation to determine if it should be a direct, routing or http driver based on the URL scheme. Then scheme is stripped off and rest of the code uses host and port string. Second time is before network connection is established. This time code parses host and port string, which is either the one used to create the driver or arrived in a routing procedure response. Scheme is missing in this case and dummy "http://" was attached just to make parser correctly handle the given string.

Turned out "url-parse" library used for parsing removes port from the parsed URL if it is the default one for the scheme. So port 80 is removed when URL scheme is "http". This made driver always treat "localhost:80" as "localhost:7687" where 7687 is the default bolt port during the second parsing step. Default port 80 was removed and driver treated absence of the port as a sign to use the default bolt port. Same logic handles URLs like "bolt://localhost". Removal of the default port is problematic because driver can't know if no port was specified or default port was specified. Experimental HTTP and HTTPS support also suffers from the same problem. Default port for HTTP should be 7474 and not 80.

This PR fixes the problem by using a different parsing library "uri-js" that always preserves the port. Dummy "http://" prefix is also changed to "none://" just in case.

URLs are currently parsed in two places in the driver. First is before
driver creation to determine if it should be a direct, routing or http
driver based on the URL scheme. Then scheme is stripped off and rest of
the code uses host and port string. Second time is before network
connection is established. This time code parses host and port string,
which is either the one used to create the driver or arrived in a
routing procedure response. Scheme is missing in this case and dummy
"http://" was attached just to make parser correctly handle the given
string.

Turned out "url-parse" library used for parsing removes port from the
parsed URL if it is the default one for the scheme. So port 80 is
removed when URL scheme is "http". This made driver always treat
"localhost:80" as "localhost:7687" where 7687 is the default bolt port
during the second parsing step. Default port 80 was removed and driver
treated absence of the port as a sign to use the default bolt port.
Same logic handles URLs like "bolt://localhost". Removal of the default
port is problematic because driver can't know if no port was specified
or default port was specified. Experimental HTTP and HTTPS support also
suffers from the same problem. Default port for HTTP should be 7474
and not 80.

This commit fixes the problem by using a different parsing library
"uri-js" that always preserves the port. Dummy "http://" prefix is
also changed to "none://" just in case.
To clarify that address being used for connection is not a URL but
a host-port string.
@lutovich lutovich requested a review from ali-ince April 30, 2018 12:06
@ali-ince ali-ince merged commit 04379dd into neo4j:1.6 Apr 30, 2018
@lutovich lutovich deleted the 1.6-port-80 branch April 30, 2018 12:49
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.

2 participants