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

Force HTTP check under corresponding protocols #56

Merged
merged 1 commit into from
May 5, 2022

Conversation

solarispika
Copy link
Contributor

Fixes #55.

Since URL object with http or https protocol and default port(80 or 443)
will not show the port, the port is only assigned to default port 443
when the protocol is neither one of them.

@sindresorhus
Copy link
Owner

CI is failing

@solarispika
Copy link
Contributor Author

The failed test tests imap.gmail.com:995 which is prepended with http:// before testing.
I see comment on target says: Protocols other than http: and https: are not supported.
I'm not sure if the test have its purpose or it can be removed?
Or maybe we can only force HTTP check when the target is explicitly using HTTP?

index.js Outdated
@@ -38,10 +38,11 @@ const checkHttp = async (url, timeout) => {
const getAddress = async hostname => net.isIP(hostname) ? hostname : (await dnsLookupP(hostname)).address;

const isTargetReachable = timeout => async target => {
const isHTTP = ['http:', 'https:'].some(prot => target.indexOf(prot) === 0);
Copy link
Owner

Choose a reason for hiding this comment

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

This is overly complicated.

Suggested change
const isHTTP = ['http:', 'https:'].some(prot => target.indexOf(prot) === 0);
const isHTTP = target.startsWith('https://') || target.startsWith('http://');

@sindresorhus
Copy link
Owner

Or maybe we can only force HTTP check when the target is explicitly using HTTP?

Isn't that what we are already doing now?

@sindresorhus
Copy link
Owner

I'm not sure if the test have its purpose or it can be removed?

I would recommend "git blaming" it and check why it was added.

Since URL object with http or https protocol and default port(80 or 443)
will not show the port, the port is only assigned to default port 443
when the protocol is neither one of them.
@solarispika
Copy link
Contributor Author

#38 removed support for other well-known protocol, so it changed the test of ftp url to the current one.
The words "Protocols other than http: and https: are not supported." does not limit the use of other ports.
I think it is fine to leave the test now.

@sindresorhus sindresorhus merged commit d753f49 into sindresorhus:main May 5, 2022
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 non-default HTTP ports
2 participants