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

refactor: parse default http ports in url, fixes #59 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harshalmittal4
Copy link

This change correctly parses default http ports in url for rest and grpc packages.

This change correctly parses default http
ports in url for rest and grpc packages.
@@ -47,7 +47,9 @@ export class QdrantClient {
}
const parsedUrl = new URL(url);
this._host = parsedUrl.hostname;
this._port = parsedUrl.port ? Number(parsedUrl.port) : port;
const getPort = (url: string): number | null =>
url.includes(':443') ? 443 : url.includes(':80') ? 80 : port;
Copy link
Member

Choose a reason for hiding this comment

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

what if url has localhost:8000? url.includes(':80') will still match

Copy link
Author

@harshalmittal4 harshalmittal4 Mar 7, 2024

Choose a reason for hiding this comment

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

In that case parsedUrl.port on line 52 will return 8000, so getPort will not be invoked.

Copy link
Member

Choose a reason for hiding this comment

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

ok, in which case getPort will be invoked? If port is not specified explicitly? If so, why are we doing those checks for url.includes?

Copy link
Author

Choose a reason for hiding this comment

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

Invoked in case of urls having default ports (443 for https and 80 for http) or no port specified.
#61 (comment)

Copy link
Member

@generall generall left a comment

Choose a reason for hiding this comment

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

I probably need a bit more context of what this PR fixes

@harshalmittal4
Copy link
Author

harshalmittal4 commented Mar 7, 2024

Thanks for looking @generall , @kartik-gupta-ij

For context, the url parser const parsedUrl = new URL(url); when used with urls having default ports (443 for https and 80 for http) returns empty string, which is mentioned in their docs as well. As a reult, when a user sends a url with 443 or 80, qdrant's default port gets used (6333 for rest and 6334 for grpc).

This change fixes this behavior. The issue was seen here - #59

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.

3 participants