Comparing version 4.4.5 to 4.4.6
@@ -9,3 +9,3 @@ // Ported from https://github.com/nodejs/undici/pull/907 | ||
const util = require('../core/util') | ||
const { ReadableStreamFrom } = require('../fetch/util') | ||
const { ReadableStreamFrom, toUSVString } = require('../fetch/util') | ||
@@ -102,8 +102,8 @@ let Blob | ||
// https://fetch.spec.whatwg.org/#dom-body-text | ||
text () { | ||
return consume(this, 'text') | ||
async text () { | ||
return toUSVString(await consume(this, 'text')) | ||
} | ||
// https://fetch.spec.whatwg.org/#dom-body-json | ||
json () { | ||
async json () { | ||
return consume(this, 'json') | ||
@@ -113,3 +113,3 @@ } | ||
// https://fetch.spec.whatwg.org/#dom-body-blob | ||
blob () { | ||
async blob () { | ||
return consume(this, 'blob') | ||
@@ -119,3 +119,3 @@ } | ||
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer | ||
arrayBuffer () { | ||
async arrayBuffer () { | ||
return consume(this, 'arrayBuffer') | ||
@@ -125,3 +125,3 @@ } | ||
// https://fetch.spec.whatwg.org/#dom-body-formdata | ||
formData () { | ||
async formData () { | ||
// TODO: Implement. | ||
@@ -128,0 +128,0 @@ throw new NotSupportedError() |
@@ -387,68 +387,74 @@ 'use strict' | ||
let mod | ||
try { | ||
mod = new WebAssembly.Module(readFileSync(resolve(__dirname, './llhttp/llhttp_simd.wasm'))) | ||
} catch (e) { | ||
/* istanbul ignore next */ | ||
let llhttpInstance | ||
function lazyllhttp () { | ||
if (!llhttpInstance) { | ||
let mod | ||
try { | ||
mod = new WebAssembly.Module(readFileSync(resolve(__dirname, './llhttp/llhttp_simd.wasm'))) | ||
} catch (e) { | ||
/* istanbul ignore next */ | ||
// We could check if the error was caused by the simd option not | ||
// being enabled, but the occurring of this other error | ||
// * https://github.com/emscripten-core/emscripten/issues/11495 | ||
// got me to remove that check to avoid breaking Node 12. | ||
mod = new WebAssembly.Module(readFileSync(resolve(__dirname, './llhttp/llhttp.wasm'))) | ||
} | ||
// We could check if the error was caused by the simd option not | ||
// being enabled, but the occurring of this other error | ||
// * https://github.com/emscripten-core/emscripten/issues/11495 | ||
// got me to remove that check to avoid breaking Node 12. | ||
mod = new WebAssembly.Module(readFileSync(resolve(__dirname, './llhttp/llhttp.wasm'))) | ||
} | ||
const llhttp = new WebAssembly.Instance(mod, { | ||
env: { | ||
/* eslint-disable camelcase */ | ||
llhttpInstance = new WebAssembly.Instance(mod, { | ||
env: { | ||
/* eslint-disable camelcase */ | ||
wasm_on_url: (p, at, len) => { | ||
/* istanbul ignore next */ | ||
return 0 | ||
}, | ||
wasm_on_status: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onStatus(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_message_begin: (p) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onMessageBegin() || 0 | ||
}, | ||
wasm_on_header_field: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onHeaderField(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_header_value: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onHeaderValue(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onHeadersComplete(statusCode, Boolean(upgrade), Boolean(shouldKeepAlive)) || 0 | ||
}, | ||
wasm_on_body: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onBody(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_message_complete: (p) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onMessageComplete() || 0 | ||
} | ||
wasm_on_url: (p, at, len) => { | ||
/* istanbul ignore next */ | ||
return 0 | ||
}, | ||
wasm_on_status: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onStatus(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_message_begin: (p) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onMessageBegin() || 0 | ||
}, | ||
wasm_on_header_field: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onHeaderField(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_header_value: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onHeaderValue(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onHeadersComplete(statusCode, Boolean(upgrade), Boolean(shouldKeepAlive)) || 0 | ||
}, | ||
wasm_on_body: (p, at, len) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
const start = at - currentBufferPtr | ||
const end = start + len | ||
return currentParser.onBody(currentBufferRef.slice(start, end)) || 0 | ||
}, | ||
wasm_on_message_complete: (p) => { | ||
assert.strictEqual(currentParser.ptr, p) | ||
return currentParser.onMessageComplete() || 0 | ||
} | ||
/* eslint-enable camelcase */ | ||
/* eslint-enable camelcase */ | ||
} | ||
}) | ||
} | ||
}) | ||
return llhttpInstance | ||
} | ||
let currentParser = null | ||
let currentBufferRef = null | ||
let currentBufferSize = 16384 | ||
let currentBufferPtr = llhttp.exports.malloc(currentBufferSize) | ||
let currentBufferSize = 0 | ||
let currentBufferPtr = null | ||
@@ -463,3 +469,4 @@ const TIMEOUT_HEADERS = 1 | ||
this.ptr = llhttp.exports.llhttp_alloc(constants.TYPE.RESPONSE) | ||
this.llhttp = lazyllhttp().exports | ||
this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE) | ||
this.client = client | ||
@@ -521,3 +528,3 @@ this.socket = socket | ||
llhttp.exports.llhttp_resume(this.ptr) | ||
this.llhttp.llhttp_resume(this.ptr) | ||
@@ -552,12 +559,14 @@ assert(this.timeoutType === TIMEOUT_BODY) | ||
const { socket } = this | ||
const { socket, llhttp } = this | ||
if (data.length > currentBufferSize) { | ||
llhttp.exports.free(currentBufferPtr) | ||
if (currentBufferPtr) { | ||
llhttp.free(currentBufferPtr) | ||
} | ||
currentBufferSize = Math.ceil(data.length / 4096) * 4096 | ||
currentBufferPtr = llhttp.exports.malloc(currentBufferSize) | ||
currentBufferPtr = llhttp.malloc(currentBufferSize) | ||
} | ||
// TODO (perf): Can we avoid this copy somehow? | ||
new Uint8Array(llhttp.exports.memory.buffer, currentBufferPtr, currentBufferSize).set(data) | ||
new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize).set(data) | ||
@@ -574,3 +583,3 @@ // Call `execute` on the wasm parser. | ||
currentParser = this | ||
ret = llhttp.exports.llhttp_execute(this.ptr, currentBufferPtr, data.length) | ||
ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, data.length) | ||
/* eslint-disable-next-line no-useless-catch */ | ||
@@ -585,3 +594,3 @@ } catch (err) { | ||
const offset = llhttp.exports.llhttp_get_error_pos(this.ptr) - currentBufferPtr | ||
const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr | ||
@@ -594,8 +603,8 @@ if (ret === constants.ERROR.PAUSED_UPGRADE) { | ||
} else if (ret !== constants.ERROR.OK) { | ||
const ptr = llhttp.exports.llhttp_get_error_reason(this.ptr) | ||
const ptr = llhttp.llhttp_get_error_reason(this.ptr) | ||
let message = '' | ||
/* istanbul ignore else: difficult to make a test case for */ | ||
if (ptr) { | ||
const len = new Uint8Array(llhttp.exports.memory.buffer, ptr).indexOf(0) | ||
message = Buffer.from(llhttp.exports.memory.buffer, ptr, len).toString() | ||
const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0) | ||
message = Buffer.from(llhttp.memory.buffer, ptr, len).toString() | ||
} | ||
@@ -632,3 +641,3 @@ throw new HTTPParserError(message, constants.ERROR[ret], data.slice(offset)) | ||
currentParser = this | ||
llhttp.exports.llhttp_finish(this.ptr) // TODO (fix): Check ret? | ||
this.llhttp.llhttp_finish(this.ptr) // TODO (fix): Check ret? | ||
} finally { | ||
@@ -657,3 +666,3 @@ currentParser = null | ||
llhttp.exports.llhttp_free(this.ptr) | ||
this.llhttp.llhttp_free(this.ptr) | ||
this.ptr = null | ||
@@ -660,0 +669,0 @@ |
'use strict' | ||
const util = require('../core/util') | ||
const { ReadableStreamFrom } = require('./util') | ||
const { ReadableStreamFrom, toUSVString } = require('./util') | ||
const { FormData } = require('./formdata') | ||
@@ -78,4 +78,5 @@ const { kState } = require('./symbols') | ||
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */ | ||
const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22') | ||
const normalizeLinefeeds = value => value.replace(/\r?\n|\r/g, '\r\n') | ||
const escape = (str) => | ||
str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22') | ||
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n') | ||
@@ -98,3 +99,4 @@ // Set action to this step: run the multipart/form-data | ||
`; name="${escape(normalizeLinefeeds(name))}"` + | ||
(value.filename ? `; filename="${escape(value.filename)}"` : '') + '\r\n' + | ||
(value.filename ? `; filename="${escape(value.filename)}"` : '') + | ||
'\r\n' + | ||
`Content-Type: ${ | ||
@@ -154,5 +156,4 @@ value.type || 'application/octet-stream' | ||
stream = object instanceof ReadableStream | ||
? object | ||
: ReadableStreamFrom(object) | ||
stream = | ||
object instanceof ReadableStream ? object : ReadableStreamFrom(object) | ||
} else { | ||
@@ -162,3 +163,3 @@ // TODO: byte sequence? | ||
// TODO: else? | ||
source = String(object) | ||
source = toUSVString(object) | ||
contentType = 'text/plain;charset=UTF-8' | ||
@@ -300,3 +301,3 @@ } | ||
const blob = await this.blob() | ||
return await blob.text() | ||
return toUSVString(await blob.text()) | ||
}, | ||
@@ -303,0 +304,0 @@ |
@@ -6,3 +6,3 @@ 'use strict' | ||
const { File } = require('./file') | ||
const { HTMLFormElement } = require('./util') | ||
const { HTMLFormElement, toUSVString } = require('./util') | ||
@@ -34,7 +34,7 @@ class FormData { | ||
} | ||
const name = String(args[0]) | ||
const filename = args.length === 3 ? String(args[2]) : undefined | ||
const name = toUSVString(args[0]) | ||
const filename = args.length === 3 ? toUSVString(args[2]) : undefined | ||
// 1. Let value be value if given; otherwise blobValue. | ||
const value = args[1] instanceof Blob ? args[1] : String(args[1]) | ||
const value = args[1] instanceof Blob ? args[1] : toUSVString(args[1]) | ||
@@ -58,3 +58,3 @@ // 2. Let entry be the result of creating an entry with | ||
} | ||
const name = String(args[0]) | ||
const name = toUSVString(args[0]) | ||
@@ -82,3 +82,3 @@ // The delete(name) method steps are to remove all entries whose name | ||
} | ||
const name = String(args[0]) | ||
const name = toUSVString(args[0]) | ||
@@ -106,3 +106,3 @@ // 1. If there is no entry whose name is name in this’s entry list, | ||
} | ||
const name = String(args[0]) | ||
const name = toUSVString(args[0]) | ||
@@ -127,3 +127,3 @@ // 1. If there is no entry whose name is name in this’s entry list, | ||
} | ||
const name = String(args[0]) | ||
const name = toUSVString(args[0]) | ||
@@ -149,4 +149,4 @@ // The has(name) method steps are to return true if there is an entry | ||
} | ||
const name = String(args[0]) | ||
const filename = args.length === 3 ? String(args[2]) : undefined | ||
const name = toUSVString(args[0]) | ||
const filename = args.length === 3 ? toUSVString(args[2]) : undefined | ||
@@ -157,3 +157,3 @@ // The set(name, value) and set(name, blobValue, filename) method steps | ||
// 1. Let value be value if given; otherwise blobValue. | ||
const value = args[1] instanceof Blob ? args[1] : String(args[1]) | ||
const value = args[1] instanceof Blob ? args[1] : toUSVString(args[1]) | ||
@@ -160,0 +160,0 @@ // 2. Let entry be the result of creating an entry with name, value, and |
@@ -8,4 +8,8 @@ /* globals AbortController */ | ||
const util = require('../core/util') | ||
const { isValidHTTPToken, EnvironmentSettingsObject } = require('./util') | ||
const { | ||
isValidHTTPToken, | ||
EnvironmentSettingsObject, | ||
toUSVString | ||
} = require('./util') | ||
const { | ||
forbiddenMethods, | ||
@@ -50,3 +54,3 @@ corsSafeListedMethods, | ||
} | ||
const input = args[0] instanceof Request ? args[0] : String(args[0]) | ||
const input = args[0] instanceof Request ? args[0] : toUSVString(args[0]) | ||
const init = args.length >= 1 ? args[1] ?? {} : {} | ||
@@ -53,0 +57,0 @@ |
@@ -7,3 +7,3 @@ 'use strict' | ||
const { kEnumerableProperty } = util | ||
const { responseURL, isValidReasonPhrase } = require('./util') | ||
const { responseURL, isValidReasonPhrase, toUSVString } = require('./util') | ||
const { | ||
@@ -48,3 +48,3 @@ redirectStatus, | ||
const status = args.length >= 2 ? args[1] : 302 | ||
const url = String(args[0]) | ||
const url = toUSVString(args[0]) | ||
@@ -51,0 +51,0 @@ // 1. Let parsedURL be the result of parsing url with current settings |
@@ -5,2 +5,3 @@ 'use strict' | ||
const { performance } = require('perf_hooks') | ||
const nodeUtil = require('util') | ||
@@ -294,2 +295,3 @@ let ReadableStream | ||
EnvironmentSettingsObject, | ||
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), | ||
tryUpgradeRequestToAPotentiallyTrustworthyURL, | ||
@@ -296,0 +298,0 @@ coarsenedSharedCurrentTime, |
{ | ||
"name": "undici", | ||
"version": "4.4.5", | ||
"version": "4.4.6", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
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
591480
9298