Socket
Socket
Sign inDemoInstall

undici

Package Overview
Dependencies
6
Maintainers
1
Versions
205
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

17

lib/client.js
'use strict'
/* eslint no-prototype-builtins: "off" */
const { URL } = require('url')

@@ -220,6 +222,9 @@ const net = require('net')

const cb = this[kCallbacks].shift()
this._needHeaders--
this._lastBody = new Readable({ read: this[kRead].bind(this) })
this._lastBody.push = this[kRequests].shift().wrapSimple(this._lastBody, this._lastBody.push)
const request = this[kRequests].shift()
const skipBody = request.method === 'HEAD'
if (!skipBody) {
this._lastBody = new Readable({ read: this[kRead].bind(this) })
this._lastBody.push = request.wrapSimple(this._lastBody, this._lastBody.push)
}
cb(null, {

@@ -234,2 +239,4 @@ statusCode,

}
return skipBody
}

@@ -244,3 +251,5 @@

this._lastBody = null
body.push(null)
if (body !== null) {
body.push(null)
}
}

@@ -247,0 +256,0 @@

@@ -22,3 +22,3 @@ 'use strict'

for (let client of this.clients) {
for (const client of this.clients) {
client.on('drain', onDrain)

@@ -25,0 +25,0 @@ }

{
"name": "undici",
"version": "0.4.0",
"version": "0.5.0",
"description": "An HTTP/1.1 client, written from scratch for Node.js",

@@ -23,5 +23,5 @@ "main": "index.js",

"proxyquire": "^2.0.1",
"snazzy": "^7.1.1",
"standard": "^11.0.1",
"tap": "^12.0.0"
"snazzy": "^8.0.0",
"standard": "^14.0.0",
"tap": "^14.0.0"
},

@@ -31,7 +31,7 @@ "dependencies": {

"fastq": "^1.6.0",
"readable-stream": "^2.3.6",
"http-parser-js": "^0.4.13",
"retimer": "^1.1.0",
"readable-stream": "^3.0.0",
"http-parser-js": "^0.5.2",
"retimer": "^2.0.0",
"syncthrough": "^0.5.0"
}
}

@@ -39,2 +39,27 @@ 'use strict'

test('basic head', (t) => {
t.plan(7)
const server = createServer((req, res) => {
t.strictEqual('/', req.url)
t.strictEqual('HEAD', req.method)
t.strictEqual('localhost', req.headers.host)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.close.bind(client))
client.request({ path: '/', method: 'HEAD' }, (err, { statusCode, headers, body }) => {
t.error(err)
t.strictEqual(statusCode, 200)
t.strictEqual(headers['content-type'], 'text/plain')
t.strictEqual(body, null)
})
})
})
test('get with host header', (t) => {

@@ -71,2 +96,27 @@ t.plan(7)

test('head with host header', (t) => {
t.plan(7)
const server = createServer((req, res) => {
t.strictEqual('/', req.url)
t.strictEqual('HEAD', req.method)
t.strictEqual('example.com', req.headers.host)
res.setHeader('content-type', 'text/plain')
res.end('hello from ' + req.headers.host)
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.close.bind(client))
client.request({ path: '/', method: 'HEAD', headers: { host: 'example.com' } }, (err, { statusCode, headers, body }) => {
t.error(err)
t.strictEqual(statusCode, 200)
t.strictEqual(headers['content-type'], 'text/plain')
t.strictEqual(body, null)
})
})
})
function postServer (t, expected) {

@@ -295,2 +345,29 @@ return function (req, res) {

test('10 times HEAD', (t) => {
const num = 10
t.plan(3 * 10)
const server = createServer((req, res) => {
res.end(req.url)
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.close.bind(client))
for (var i = 0; i < num; i++) {
makeRequest(i)
}
function makeRequest (i) {
client.request({ path: '/' + i, method: 'HEAD' }, (err, { statusCode, headers, body }) => {
t.error(err)
t.strictEqual(statusCode, 200)
t.strictEqual(body, null)
})
}
})
})
test('20 times GET with pipelining 10', (t) => {

@@ -354,2 +431,54 @@ const num = 20

test('20 times HEAD with pipelining 10', (t) => {
const num = 20
t.plan(3 * num + 1)
let count = 0
let countGreaterThanOne = false
const server = createServer((req, res) => {
count++
setTimeout(function () {
countGreaterThanOne = countGreaterThanOne || count > 1
res.end(req.url)
}, 10)
})
t.tearDown(server.close.bind(server))
// needed to check for a warning on the maxListeners on the socket
process.on('warning', t.fail)
t.tearDown(() => {
process.removeListener('warning', t.fail)
})
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 10
})
t.tearDown(client.close.bind(client))
for (let i = 0; i < num; i++) {
makeRequest(i)
}
function makeRequest (i) {
makeHeadRequestAndExpectUrl(client, i, t, () => {
count--
if (i === num - 1) {
t.ok(countGreaterThanOne, 'seen more than one parallel request')
}
})
}
})
})
function makeHeadRequestAndExpectUrl (client, i, t, cb) {
return client.request({ path: '/' + i, method: 'HEAD' }, (err, { statusCode, headers, body }) => {
cb()
t.error(err)
t.strictEqual(statusCode, 200)
t.strictEqual(body, null)
})
}
test('A client should enqueue as much as twice its pipelining factor', (t) => {

@@ -356,0 +485,0 @@ const num = 10

@@ -84,3 +84,3 @@ 'use strict'

const pool = new Pool(`http://notanhost`)
const pool = new Pool('http://notanhost')

@@ -87,0 +87,0 @@ t.strictEqual(total, 10)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc