Comparing version 1.2.3 to 1.2.4
@@ -16,2 +16,3 @@ 'use strict' | ||
const util = require('./util') | ||
const assert = require('assert') | ||
const { kResume, kEnqueue } = require('./symbols') | ||
@@ -32,6 +33,3 @@ | ||
if (!callback) { | ||
return | ||
} | ||
assert(callback) | ||
this.callback = null | ||
@@ -47,5 +45,3 @@ this.res = callback.call(this, null, { | ||
_onBody (chunk, offset, length) { | ||
if (this.res) { | ||
return this.res(null, chunk.slice(offset, offset + length)) | ||
} | ||
return this.res(null, chunk.slice(offset, offset + length)) | ||
} | ||
@@ -56,7 +52,5 @@ | ||
if (this.res) { | ||
const res = this.res | ||
this.res = null | ||
res(null, null) | ||
} | ||
const res = this.res | ||
this.res = null | ||
res(null, null) | ||
} | ||
@@ -113,7 +107,3 @@ | ||
if (request) { | ||
request.runInAsyncScope(callback, null, err, null) | ||
} else { | ||
callback(err, null) | ||
} | ||
request.runInAsyncScope(callback, null, err, null) | ||
} | ||
@@ -147,15 +137,13 @@ }) | ||
util.destroy(res, err) | ||
if (request) { | ||
if (err) { | ||
request.onError(err) | ||
} | ||
request.runInAsyncScope( | ||
callback, | ||
null, | ||
err, | ||
null | ||
) | ||
} else { | ||
callback(err, null) | ||
if (err) { | ||
request.onError(err) | ||
} | ||
request.runInAsyncScope( | ||
callback, | ||
null, | ||
err, | ||
null | ||
) | ||
} | ||
@@ -162,0 +150,0 @@ }).on('prefinish', () => { |
@@ -12,3 +12,4 @@ 'use strict' | ||
const { kEnqueue } = require('./symbols') | ||
const { assert } = require('console') | ||
const assert = require('assert') | ||
class StreamRequest extends Request { | ||
@@ -85,13 +86,11 @@ constructor (client, opts, factory, callback) { | ||
if (res) { | ||
this.res = null | ||
if (!res.readable) { | ||
util.destroy(res, err) | ||
} | ||
assert(res) | ||
this.res = null | ||
if (!res.readable) { | ||
util.destroy(res) | ||
} | ||
if (callback) { | ||
this.callback = null | ||
callback(null, null) | ||
} | ||
assert(callback) | ||
this.callback = null | ||
callback(null, null) | ||
}) | ||
@@ -123,6 +122,5 @@ | ||
if (callback) { | ||
this.callback = null | ||
process.nextTick(callback, err, null) | ||
} | ||
assert(callback) | ||
this.callback = null | ||
process.nextTick(callback, err, null) | ||
@@ -129,0 +127,0 @@ if (res) { |
@@ -233,2 +233,3 @@ 'use strict' | ||
/* istanbul ignore next: only used for test */ | ||
[kConnect] (cb) { | ||
@@ -385,2 +386,6 @@ connect(this) | ||
[HTTPParser.kOnTimeout] () { | ||
if (this.statusCode) { | ||
// https://github.com/mcollina/undici/issues/268 | ||
return | ||
} | ||
util.destroy(this.socket, new HeadersTimeoutError()) | ||
@@ -395,7 +400,3 @@ } | ||
if (ret instanceof Error) { | ||
const err = ret | ||
if (typeof err.reason === 'string') { | ||
err.message = `Parse Error: ${err.reason}` | ||
} | ||
util.destroy(this.socket, err) | ||
util.destroy(this.socket, ret) | ||
} else { | ||
@@ -434,3 +435,3 @@ // When the underlying `net.Socket` instance is consumed - no | ||
if (statusCode < 200) { | ||
request.onInfo(statusCode, util.parseHeaders(rawHeaders, headers)) | ||
// request.onInfo(statusCode, util.parseHeaders(rawHeaders, headers)) | ||
} else { | ||
@@ -446,6 +447,3 @@ request.onHeaders(statusCode, util.parseHeaders(rawHeaders, headers), resumeSocket) | ||
if (statusCode < 200) { | ||
util.destroy(socket, new SocketError('unexpected request body')) | ||
return | ||
} | ||
assert(statusCode >= 200) | ||
@@ -471,2 +469,5 @@ const request = client[kQueue][client[kRunningIdx]] | ||
this.statusCode = null | ||
this.headers = null | ||
if (statusCode < 200) { | ||
@@ -476,5 +477,2 @@ return | ||
this.statusCode = null | ||
this.headers = null | ||
request.onComplete(headers) | ||
@@ -547,2 +545,3 @@ | ||
const tlsOpts = { ...client[kTLSOpts], servername } | ||
/* istanbul ignore next: https://github.com/mcollina/undici/issues/267 */ | ||
socket = client[kSocketPath] | ||
@@ -582,3 +581,3 @@ ? tls.connect(client[kSocketPath], tlsOpts) | ||
}) | ||
.on('data', function () { | ||
.on('data', /* istanbul ignore next */ function () { | ||
/* istanbul ignore next */ | ||
@@ -716,10 +715,6 @@ assert(false) | ||
if (client[kReset]) { | ||
if (client[kWriting] || client[kReset]) { | ||
return | ||
} | ||
if (client[kWriting]) { | ||
return | ||
} | ||
if (client.running && !request.idempotent) { | ||
@@ -734,7 +729,7 @@ // Non-idempotent request cannot be retried. | ||
request.body | ||
.on('data', function () { | ||
.on('data', /* istanbul ignore next */ function () { | ||
/* istanbul ignore next */ | ||
assert(false) | ||
}) | ||
.on('error', function (err) { | ||
util.destroy(this) | ||
request.onError(err) | ||
@@ -745,2 +740,3 @@ }) | ||
}) | ||
request.body = null | ||
@@ -837,3 +833,4 @@ } | ||
client[kReset] = !expectsPayload | ||
} else if (util.isStream(body)) { | ||
} else { | ||
assert(util.isStream(body)) | ||
assert(contentLength !== 0 || !client.running, 'stream body cannot be pipelined') | ||
@@ -949,5 +946,2 @@ | ||
client[kWriting] = true | ||
} else { | ||
/* istanbul ignore next */ | ||
assert(false) | ||
} | ||
@@ -954,0 +948,0 @@ |
@@ -160,12 +160,2 @@ 'use strict' | ||
onInfo (statusCode, headers) { | ||
if (this.aborted) { | ||
return | ||
} | ||
if (this._onInfo) { | ||
this.runInAsyncScope(this._onInfo, this, statusCode, headers) | ||
} | ||
} | ||
onHeaders (statusCode, headers, resume) { | ||
@@ -172,0 +162,0 @@ if (this.aborted) { |
{ | ||
"name": "undici", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -842,1 +842,55 @@ 'use strict' | ||
}) | ||
test('pipeline CONNECT throw', (t) => { | ||
t.plan(1) | ||
const server = createServer((req, res) => { | ||
res.end('asd') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`) | ||
t.tearDown(client.destroy.bind(client)) | ||
client.pipeline({ | ||
path: '/', | ||
method: 'CONNECT' | ||
}, () => { | ||
t.fail() | ||
}).on('error', (err) => { | ||
t.ok(err instanceof errors.NotSupportedError) | ||
}) | ||
client.on('disconnect', () => { | ||
t.fail() | ||
}) | ||
}) | ||
}) | ||
test('pipeline body without destroy', (t) => { | ||
t.plan(1) | ||
const server = createServer((req, res) => { | ||
res.end('asd') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`) | ||
t.tearDown(client.destroy.bind(client)) | ||
client.pipeline({ | ||
path: '/', | ||
method: 'GET' | ||
}, ({ body }) => { | ||
const pt = new PassThrough({ autoDestroy: false }) | ||
pt.destroy = null | ||
return body.pipe(pt) | ||
}) | ||
.end() | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
.resume() | ||
}) | ||
}) |
@@ -384,1 +384,116 @@ 'use strict' | ||
}) | ||
test('pipelining HEAD busy', (t) => { | ||
t.plan(6) | ||
const server = createServer() | ||
server.on('request', (req, res) => { | ||
res.end('asd') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`, { | ||
pipelining: 10 | ||
}) | ||
t.tearDown(client.close.bind(client)) | ||
{ | ||
const body = new Readable({ | ||
read () { } | ||
}) | ||
client.request({ | ||
path: '/', | ||
method: 'GET', | ||
body | ||
}, (err, data) => { | ||
t.error(err) | ||
data.body | ||
.resume() | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
}) | ||
body.push(null) | ||
t.strictEqual(client.busy, false) | ||
} | ||
{ | ||
const body = new Readable({ | ||
read () { } | ||
}) | ||
client.request({ | ||
path: '/', | ||
method: 'HEAD', | ||
body | ||
}, (err, data) => { | ||
t.error(err) | ||
data.body | ||
.resume() | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
}) | ||
body.push(null) | ||
t.strictEqual(client.busy, true) | ||
} | ||
}) | ||
}) | ||
test('pipelining idempotent busy', (t) => { | ||
t.plan(6) | ||
const server = createServer() | ||
server.on('request', (req, res) => { | ||
res.end('asd') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`, { | ||
pipelining: 10 | ||
}) | ||
t.tearDown(client.close.bind(client)) | ||
{ | ||
const body = new Readable({ | ||
read () { } | ||
}) | ||
client.request({ | ||
path: '/', | ||
method: 'GET', | ||
body | ||
}, (err, data) => { | ||
t.error(err) | ||
data.body | ||
.resume() | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
}) | ||
body.push(null) | ||
t.strictEqual(client.busy, false) | ||
} | ||
{ | ||
const body = new Readable({ | ||
read () { } | ||
}) | ||
client.request({ | ||
path: '/', | ||
method: 'GET', | ||
idempotent: false, | ||
body | ||
}, (err, data) => { | ||
t.error(err) | ||
data.body | ||
.resume() | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
}) | ||
body.push(null) | ||
t.strictEqual(client.busy, true) | ||
} | ||
}) | ||
}) |
@@ -491,1 +491,31 @@ 'use strict' | ||
}) | ||
test('stream abort after complete', (t) => { | ||
t.plan(1) | ||
const server = createServer((req, res) => { | ||
res.end('asd') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`) | ||
t.tearDown(client.destroy.bind(client)) | ||
const pt = new PassThrough() | ||
const signal = new EE() | ||
client.stream({ | ||
path: '/', | ||
method: 'GET', | ||
signal | ||
}, () => { | ||
return pt | ||
}, (err) => { | ||
t.error(err) | ||
signal.emit('abort') | ||
}) | ||
client.on('disconnect', () => { | ||
t.fail() | ||
}) | ||
}) | ||
}) |
@@ -336,5 +336,5 @@ 'use strict' | ||
const expected = readFileSync(__filename, 'utf8') | ||
const expected = Buffer.alloc(2000000).toString() | ||
const server = createServer(postServer(t, expected)) | ||
const server = createServer(postServer(t, expected + expected)) | ||
t.tearDown(server.close.bind(server)) | ||
@@ -352,3 +352,3 @@ | ||
headers: { | ||
'content-length': Buffer.byteLength(expected) | ||
'content-length': Buffer.byteLength(expected) * 2 | ||
}, | ||
@@ -376,4 +376,8 @@ requestTimeout: 0, | ||
setImmediate(() => { | ||
body.emit('data', '') | ||
body.emit('data', expected) | ||
body.emit('close') | ||
client[kSocket].on('drain', () => { | ||
body.emit('data', expected) | ||
body.emit('close') | ||
}) | ||
}) | ||
@@ -435,2 +439,45 @@ }) | ||
test('basic POST with empty stream', (t) => { | ||
t.plan(4) | ||
const server = createServer(function (req, res) { | ||
t.same(req.headers['content-length'], 0) | ||
req.pipe(res) | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`) | ||
t.tearDown(client.close.bind(client)) | ||
const body = new Readable({ | ||
autoDestroy: false, | ||
read () { | ||
}, | ||
destroy (err, callback) { | ||
callback(!this._readableState.endEmitted ? new Error('asd') : err) | ||
} | ||
}).on('end', () => { | ||
process.nextTick(() => { | ||
t.strictEqual(body.destroyed, true) | ||
}) | ||
}) | ||
body.push(null) | ||
client.request({ | ||
path: '/', | ||
method: 'POST', | ||
body | ||
}, (err, { statusCode, headers, body }) => { | ||
t.error(err) | ||
body | ||
.on('data', () => { | ||
t.fail() | ||
}) | ||
.on('end', () => { | ||
t.pass() | ||
}) | ||
}) | ||
}) | ||
}) | ||
test('10 times GET', (t) => { | ||
@@ -437,0 +484,0 @@ const num = 10 |
@@ -68,1 +68,27 @@ 'use strict' | ||
}) | ||
test('error 103 body', (t) => { | ||
t.plan(2) | ||
const server = net.createServer((socket) => { | ||
socket.write('HTTP/1.1 103 Early Hints\r\n') | ||
socket.write('Content-Length: 1\r\n') | ||
socket.write('\r\n') | ||
socket.write('a\r\n') | ||
}) | ||
t.teardown(server.close.bind(server)) | ||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`) | ||
t.teardown(client.destroy.bind(client)) | ||
client.request({ | ||
path: '/', | ||
method: 'GET' | ||
}, (err) => { | ||
t.strictEqual(err.code, 'HPE_INVALID_CONSTANT') | ||
}) | ||
client.on('disconnect', () => { | ||
t.pass() | ||
}) | ||
}) | ||
}) |
@@ -5,4 +5,5 @@ 'use strict' | ||
const { Client } = require('..') | ||
const { createServer } = require('http') | ||
const pem = require('https-pem') | ||
const http = require('http') | ||
// const https = require('http') | ||
// const pem = require('https-pem') | ||
@@ -13,3 +14,3 @@ if (process.platform !== 'win32') { | ||
const server = createServer((req, res) => { | ||
const server = http.createServer((req, res) => { | ||
t.strictEqual('/', req.url) | ||
@@ -48,38 +49,40 @@ t.strictEqual('GET', req.method) | ||
test('https unix get', (t) => { | ||
t.plan(7) | ||
// test('https get with tls opts', (t) => { | ||
// t.plan(6) | ||
const server = createServer(pem, (req, res) => { | ||
t.strictEqual('/', req.url) | ||
t.strictEqual('GET', req.method) | ||
t.strictEqual('localhost', req.headers.host) | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.end('hello') | ||
}) | ||
t.tearDown(server.close.bind(server)) | ||
// const server = https.createServer(pem, (req, res) => { | ||
// t.strictEqual('/', req.url) | ||
// t.strictEqual('GET', req.method) | ||
// res.setHeader('content-type', 'text/plain') | ||
// res.end('hello') | ||
// }) | ||
// t.tearDown(server.close.bind(server)) | ||
server.listen('/var/tmp/test4.sock', () => { | ||
const client = new Client({ | ||
hostname: 'localhost', | ||
protocol: 'http:' | ||
}, { | ||
socketPath: '/var/tmp/test4.sock' | ||
}) | ||
t.tearDown(client.close.bind(client)) | ||
// server.listen('/var/tmp/test8.sock', () => { | ||
// const client = new Client({ | ||
// hostname: 'localhost', | ||
// protocol: 'https:' | ||
// }, { | ||
// socketPath: '/var/tmp/test8.sock', | ||
// tls: { | ||
// rejectUnauthorized: false | ||
// } | ||
// }) | ||
// t.tearDown(client.close.bind(client)) | ||
client.request({ path: '/', method: 'GET' }, (err, data) => { | ||
t.error(err) | ||
const { statusCode, headers, body } = data | ||
t.strictEqual(statusCode, 200) | ||
t.strictEqual(headers['content-type'], 'text/plain') | ||
const bufs = [] | ||
body.on('data', (buf) => { | ||
bufs.push(buf) | ||
}) | ||
body.on('end', () => { | ||
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) | ||
}) | ||
}) | ||
}) | ||
}) | ||
// client.request({ path: '/', method: 'GET' }, (err, data) => { | ||
// t.error(err) | ||
// const { statusCode, headers, body } = data | ||
// t.strictEqual(statusCode, 200) | ||
// t.strictEqual(headers['content-type'], 'text/plain') | ||
// const bufs = [] | ||
// body.on('data', (buf) => { | ||
// bufs.push(buf) | ||
// }) | ||
// body.on('end', () => { | ||
// t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) | ||
// }) | ||
// }) | ||
// }) | ||
// }) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250379
8120
34