From bff30d4aa7f5cb4b472a0fabd72c4a7d5a4de71d Mon Sep 17 00:00:00 2001 From: Akshay Kadam Date: Sun, 29 Sep 2019 19:10:32 +0530 Subject: [PATCH 1/2] Accept url in config --- index.d.ts | 7 +++++++ index.js | 3 ++- index.test-d.ts | 3 ++- readme.md | 7 +++++++ test.js | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index e1454b2..3c5afd6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; } } diff --git a/index.js b/index.js index 292e556..0a763b1 100644 --- a/index.js +++ b/index.js @@ -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, { family: options.version === 'v4' ? 4 : 6, headers: { 'user-agent': 'CaptiveNetworkSupport/1.0 wispr' @@ -19,6 +19,7 @@ const isOnline = options => { options = { timeout: 5000, version: 'v4', + url: 'http://captive.apple.com/hotspot-detect.html', ...options }; diff --git a/index.test-d.ts b/index.test-d.ts index 8efe05b..2e879fd 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,7 +1,8 @@ -import {expectType} from 'tsd'; +import { expectType } from 'tsd'; import isOnline = require('.'); expectType>(isOnline()); expectType>(isOnline({timeout: 10})); expectType>(isOnline({version: 'v4'})); expectType>(isOnline({version: 'v6'})); +expectType>(isOnline({url: 'http://captive.apple.com/hotspot-detect.html'})); diff --git a/readme.md b/readme.md index 2891dc0..002782e 100644 --- a/readme.md +++ b/readme.md @@ -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`
+Default: `http://captive.apple.com/hotspot-detect.html` + +URL to check if the connection is established + ## How it works diff --git a/test.js b/test.js index 1d8c533..1a54df8 100644 --- a/test.js +++ b/test.js @@ -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'})); +}); + if (!process.env.CI) { test('v6', async t => { t.true(await isOnline({version: 'v6'})); From 7ac2b455b9b005af6163e1a87506041e5ee531cd Mon Sep 17 00:00:00 2001 From: Akshay Kadam Date: Tue, 1 Oct 2019 15:18:03 +0530 Subject: [PATCH 2/2] Remove unnecessary formatting --- index.test-d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.test-d.ts b/index.test-d.ts index 2e879fd..1b508ea 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from 'tsd'; +import {expectType} from 'tsd'; import isOnline = require('.'); expectType>(isOnline());