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

Add dnsLookupIpVersion option #1264

Merged
merged 26 commits into from
Jun 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c4e4ae4
Added documentation
Giotino May 14, 2020
749e0e9
Renamed `family` to `ipFamily`
Giotino May 14, 2020
3b984ca
Renamed `ipFamily` to `ipVersion`
Giotino May 14, 2020
0a2ea29
Removed ipVersion from Defaults
Giotino May 14, 2020
095d0b4
Added some tests
Giotino May 14, 2020
236b5fa
Better DNS and IPv6 tests
Giotino May 14, 2020
b731b96
Optional "IPv6 request" test
Giotino May 14, 2020
48a7ade
Removed useless type
Giotino May 14, 2020
31d27ef
Renamed `ipVersion` to `dnsIpVersion`
Giotino May 15, 2020
c9de7e5
Merge branch 'master' into issue-1263
Giotino May 15, 2020
ebddaa3
Removed export from DnsIpFamily
Giotino May 15, 2020
15f9298
Added example to the documentation
Giotino May 16, 2020
e693c07
Update source/core/utils/dns-ip-version.ts
Giotino May 16, 2020
8947194
dns-ip-version.ts cleanup
Giotino May 16, 2020
28a74f3
Update readme.md
sindresorhus May 24, 2020
1f78181
Applied requested changes
Giotino May 24, 2020
c2c5865
Update test/http.ts
Giotino May 27, 2020
5d57c1d
Added IPv6 detection for tests
Giotino May 28, 2020
0d30db6
Update source/core/utils/dns-ip-version.ts
Giotino May 28, 2020
7e92ebc
Throw if `dnsLookupIpVersion` is invalid
Giotino May 28, 2020
5ef0ebf
Merge branch 'master' into issue-1263
Giotino May 28, 2020
7274e02
Some cleanups
Giotino May 28, 2020
54cf845
Added `family` deprecation warning
Giotino May 28, 2020
0f19d4c
Test cleanups
Giotino May 28, 2020
0237e67
Fixed IPv6 detection for tests
Giotino May 29, 2020
4a636e3
Fixed tests
Giotino Jun 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 35 additions & 16 deletions test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ import getStream = require('get-stream');
import pEvent = require('p-event');
import got, {HTTPError, UnsupportedProtocolError} from '../source';
import withServer from './helpers/with-server';
import os = require('os');

const ifaces = os.networkInterfaces();
let IPv6supported = false;
szmarczak marked this conversation as resolved.
Show resolved Hide resolved
for (const ifname in ifaces) {
if (!Object.prototype.hasOwnProperty.call(ifaces, ifname)) {
continue;
}

const iface = ifaces[ifname]!;
for (const addr of iface) {
if (addr.family === 'IPv6' && addr.internal) {
IPv6supported = true;
break;
}
}

if (IPv6supported) {
break;
}
}

const echoIp: Handler = (request, response) => {
const address = request.connection.remoteAddress;
Expand Down Expand Up @@ -269,16 +290,15 @@ test('does not destroy completed requests', withServer, async (t, server, got) =
});

test('IPv6 request', withServer, async (t, server) => {
if (!IPv6supported) {
szmarczak marked this conversation as resolved.
Show resolved Hide resolved
return;
}

server.get('/ok', echoIp);

try {
const response = await got(`http://[::1]:${server.port}/ok`);
const response = await got(`http://[::1]:${server.port}/ok`);

t.is(response.body, '::1');
} catch {
// Assumes that IPv6 is not supported
t.pass();
}
t.is(response.body, '::1');
});

test('DNS auto', withServer, async (t, server, got) => {
Expand All @@ -302,16 +322,15 @@ test('DNS IPv4', withServer, async (t, server, got) => {
});

test('DNS IPv6', withServer, async (t, server, got) => {
if (!IPv6supported) {
return;
}

server.get('/ok', echoIp);

try {
const response = await got('ok', {
dnsLookupIpVersion: 'ipv6'
});
const response = await got('ok', {
dnsLookupIpVersion: 'ipv6'
});

t.true(isIPv6(response.body));
} catch {
// Assumes that IPv6 is not supported
t.pass();
}
t.true(isIPv6(response.body));
});