Socket
Socket
Sign inDemoInstall

@zeit/fetch-cached-dns

Package Overview
Dependencies
Maintainers
18
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zeit/fetch-cached-dns - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

5

index.js

@@ -45,2 +45,7 @@ const { isIP } = require('net')

redirectOpts.headers.delete('Host')
if (opts.onRedirect) {
opts.onRedirect(redirectOpts)
}
return fetchCachedDns(location, redirectOpts)

@@ -47,0 +52,0 @@ } else {

2

package.json
{
"name": "@zeit/fetch-cached-dns",
"version": "1.0.3",
"version": "1.1.0",
"description": "A decorator on top of `fetch` that caches the DNS query of the `hostname` of the passed URL",

@@ -5,0 +5,0 @@ "scripts": {

@@ -11,2 +11,6 @@ # fetch-cached-dns

Since this implementation is implementing redirects we are providing an `onRedirect` extra
option to the `fetch` call that allows one to customize the redirect options just before it
happens.
*NOTE: if the fetch implementation is not supplied, it will attempt to use peerDep `node-fetch`*

@@ -24,3 +24,3 @@ /* eslint-env jest*/

test('works with redirects', async () => {
test('works with absolute redirects', async () => {
let portA

@@ -52,2 +52,26 @@ let portB

test('works with relative redirects', async () => {
let count = 0
const server = createServer((req, res) => {
if (count === 0) {
res.setHeader('Location', `/foo`)
res.statusCode = 302
res.end()
} else {
res.end(req.url)
}
count++
})
await listen(server)
const { port } = server.address()
const res = await cachedDNSFetch(`http://localtest.me:${port}`)
expect(count).toBe(2)
expect(await res.status).toBe(200)
expect(await res.text()).toBe(`/foo`)
server.close()
})
test('works with `headers` as an Object', async () => {

@@ -69,1 +93,32 @@ const server = createServer((req, res) => {

})
test('works with `onRedirect` option to customize opts', async () => {
let count = 0
const server = createServer((req, res) => {
if (count === 0) {
res.setHeader('Location', `/foo`)
res.statusCode = 302
res.end()
} else {
res.end(req.url)
}
count++
})
await listen(server)
const { port } = server.address()
const options = {
onRedirect: jest.fn(opts => {
opts.randomOption = true
})
}
await cachedDNSFetch(`http://localtest.me:${port}`, options)
expect(options.onRedirect.mock.calls.length).toBe(1)
expect(options.onRedirect.mock.calls[0][0].headers).toBeDefined()
expect(options.onRedirect.mock.calls[0][0].randomOption).toBe(true)
server.close()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc