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

Accept url in config #67

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ declare namespace isOnline {
@default 'v4'
*/
readonly version?: 'v4' | 'v6';

/**
URL to check if the connection is established

@url 'http://captive.apple.com/hotspot-detect.html'
*/
readonly url?: string;
}
}

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pAny = require('p-any');
const pTimeout = require('p-timeout');

const appleCheck = async options => {
const {body} = await got('http://captive.apple.com/hotspot-detect.html', {
const {body} = await got(options.url, {
Copy link
Owner

Choose a reason for hiding this comment

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

You cannot just change the URL here. Look at the surrounding code. (https://github.com/sindresorhus/is-online/pull/67/files#diff-168726dbe96b3ce427e7fedce31bb0bcR15)

family: options.version === 'v4' ? 4 : 6,
headers: {
'user-agent': 'CaptiveNetworkSupport/1.0 wispr'
Expand All @@ -19,6 +19,7 @@ const isOnline = options => {
options = {
timeout: 5000,
version: 'v4',
url: 'http://captive.apple.com/hotspot-detect.html',
...options
};

Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ expectType<Promise<boolean>>(isOnline());
expectType<Promise<boolean>>(isOnline({timeout: 10}));
expectType<Promise<boolean>>(isOnline({version: 'v4'}));
expectType<Promise<boolean>>(isOnline({version: 'v6'}));
expectType<Promise<boolean>>(isOnline({url: 'http://captive.apple.com/hotspot-detect.html'}));
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ Default: `'v4'`

Internet Protocol version to use. This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.

##### url

Type: `string`<br>
Default: `http://captive.apple.com/hotspot-detect.html`

URL to check if the connection is established


## How it works

Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test('v4 with impossible timeout', async t => {
t.false(await isOnline({timeout: 1}));
});

test('check url', async t => {
t.true(await isOnline({url: 'https://google.com'}));
Copy link
Owner

Choose a reason for hiding this comment

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

You're not actually testing the url option here as the IP checks are faster. You need to mock those out.

});

if (!process.env.CI) {
test('v6', async t => {
t.true(await isOnline({version: 'v6'}));
Expand Down