Skip to content

Commit 220916f

Browse files
nodejs-github-botUlisesGascon
authored andcommitted
deps: update undici to 5.27.0
PR-URL: #50463 Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 408fd90 commit 220916f

15 files changed

Lines changed: 251 additions & 183 deletions

File tree

‎deps/undici/src/index-fetch.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
constfetchImpl=require('./lib/fetch').fetch
44

5-
module.exports.fetch=asyncfunctionfetch(resource,init=undefined){
6-
try{
7-
returnawaitfetchImpl(resource,init)
8-
}catch(err){
5+
module.exports.fetch=functionfetch(resource,init=undefined){
6+
returnfetchImpl(resource,init).catch((err)=>{
97
Error.captureStackTrace(err,this)
108
throwerr
11-
}
9+
})
1210
}
1311
module.exports.FormData=require('./lib/fetch/formdata').FormData
1412
module.exports.Headers=require('./lib/fetch/headers').Headers

‎deps/undici/src/lib/core/request.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ class Request {
222222
if(channels.bodySent.hasSubscribers){
223223
channels.bodySent.publish({request: this})
224224
}
225+
226+
if(this[kHandler].onRequestSent){
227+
try{
228+
this[kHandler].onRequestSent()
229+
}catch(err){
230+
this.onError(err)
231+
}
232+
}
225233
}
226234

227235
onConnect(abort){

‎deps/undici/src/lib/fetch/body.js‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ let ReadableStream = globalThis.ReadableStream
2626

2727
/** @type {globalThis['File']} */
2828
constFile=NativeFile??UndiciFile
29+
consttextEncoder=newTextEncoder()
30+
consttextDecoder=newTextDecoder()
2931

3032
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
3133
functionextractBody(object,keepalive=false){
@@ -49,7 +51,7 @@ function extractBody (object, keepalive = false) {
4951
stream=newReadableStream({
5052
asyncpull(controller){
5153
controller.enqueue(
52-
typeofsource==='string' ? newTextEncoder().encode(source) : source
54+
typeofsource==='string' ? textEncoder.encode(source) : source
5355
)
5456
queueMicrotask(()=>readableStreamClose(controller))
5557
},
@@ -119,21 +121,20 @@ function extractBody (object, keepalive = false) {
119121
// - That the content-length is calculated in advance.
120122
// - And that all parts are pre-encoded and ready to be sent.
121123

122-
constenc=newTextEncoder()
123124
constblobParts=[]
124125
constrn=newUint8Array([13,10])// '\r\n'
125126
length=0
126127
lethasUnknownSizeValue=false
127128

128129
for(const[name,value]ofobject){
129130
if(typeofvalue==='string'){
130-
constchunk=enc.encode(prefix+
131+
constchunk=textEncoder.encode(prefix+
131132
`; name="${escape(normalizeLinefeeds(name))}"`+
132133
`\r\n\r\n${normalizeLinefeeds(value)}\r\n`)
133134
blobParts.push(chunk)
134135
length+=chunk.byteLength
135136
}else{
136-
constchunk=enc.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"`+
137+
constchunk=textEncoder.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"`+
137138
(value.name ? `; filename="${escape(value.name)}"` : '')+'\r\n'+
138139
`Content-Type: ${
139140
value.type||'application/octet-stream'
@@ -147,7 +148,7 @@ function extractBody (object, keepalive = false) {
147148
}
148149
}
149150

150-
constchunk=enc.encode(`--${boundary}--`)
151+
constchunk=textEncoder.encode(`--${boundary}--`)
151152
blobParts.push(chunk)
152153
length+=chunk.byteLength
153154
if(hasUnknownSizeValue){
@@ -445,14 +446,16 @@ function bodyMixinMethods (instance) {
445446
lettext=''
446447
// application/x-www-form-urlencoded parser will keep the BOM.
447448
// https://url.spec.whatwg.org/#concept-urlencoded-parser
448-
consttextDecoder=newTextDecoder('utf-8',{ignoreBOM: true})
449+
// Note that streaming decoder is stateful and cannot be reused
450+
conststreamingDecoder=newTextDecoder('utf-8',{ignoreBOM: true})
451+
449452
forawait(constchunkofconsumeBody(this[kState].body)){
450453
if(!isUint8Array(chunk)){
451454
thrownewTypeError('Expected Uint8Array chunk')
452455
}
453-
text+=textDecoder.decode(chunk,{stream: true})
456+
text+=streamingDecoder.decode(chunk,{stream: true})
454457
}
455-
text+=textDecoder.decode()
458+
text+=streamingDecoder.decode()
456459
entries=newURLSearchParams(text)
457460
}catch(err){
458461
// istanbul ignore next: Unclear when new URLSearchParams can fail on a string.
@@ -567,7 +570,7 @@ function utf8DecodeBytes (buffer) {
567570

568571
// 3. Process a queue with an instance of UTF-8’s
569572
// decoder, ioQueue, output, and "replacement".
570-
constoutput=newTextDecoder().decode(buffer)
573+
constoutput=textDecoder.decode(buffer)
571574

572575
// 4. Return output.
573576
returnoutput

‎deps/undici/src/lib/fetch/constants.js‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
const{ MessageChannel, receiveMessageOnPort }=require('worker_threads')
44

55
constcorsSafeListedMethods=['GET','HEAD','POST']
6+
constcorsSafeListedMethodsSet=newSet(corsSafeListedMethods)
67

78
constnullBodyStatus=[101,204,205,304]
89

910
constredirectStatus=[301,302,303,307,308]
11+
constredirectStatusSet=newSet(redirectStatus)
1012

1113
// https://fetch.spec.whatwg.org/#block-bad-port
1214
constbadPorts=[
@@ -18,6 +20,8 @@ const badPorts = [
1820
'10080'
1921
]
2022

23+
constbadPortsSet=newSet(badPorts)
24+
2125
// https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
2226
constreferrerPolicy=[
2327
'',
@@ -30,10 +34,12 @@ const referrerPolicy = [
3034
'strict-origin-when-cross-origin',
3135
'unsafe-url'
3236
]
37+
constreferrerPolicySet=newSet(referrerPolicy)
3338

3439
constrequestRedirect=['follow','manual','error']
3540

3641
constsafeMethods=['GET','HEAD','OPTIONS','TRACE']
42+
constsafeMethodsSet=newSet(safeMethods)
3743

3844
constrequestMode=['navigate','same-origin','no-cors','cors']
3945

@@ -68,6 +74,7 @@ const requestDuplex = [
6874

6975
// http://fetch.spec.whatwg.org/#forbidden-method
7076
constforbiddenMethods=['CONNECT','TRACE','TRACK']
77+
constforbiddenMethodsSet=newSet(forbiddenMethods)
7178

7279
constsubresource=[
7380
'audio',
@@ -83,6 +90,7 @@ const subresource = [
8390
'xslt',
8491
''
8592
]
93+
constsubresourceSet=newSet(subresource)
8694

8795
/** @type {globalThis['DOMException']} */
8896
constDOMException=globalThis.DOMException??(()=>{
@@ -132,5 +140,12 @@ module.exports = {
132140
nullBodyStatus,
133141
safeMethods,
134142
badPorts,
135-
requestDuplex
143+
requestDuplex,
144+
subresourceSet,
145+
badPortsSet,
146+
redirectStatusSet,
147+
corsSafeListedMethodsSet,
148+
safeMethodsSet,
149+
forbiddenMethodsSet,
150+
referrerPolicySet
136151
}

‎deps/undici/src/lib/fetch/file.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { isBlobLike } = require('./util')
77
const{ webidl }=require('./webidl')
88
const{ parseMIMEType, serializeAMimeType }=require('./dataURL')
99
const{ kEnumerableProperty }=require('../core/util')
10+
constencoder=newTextEncoder()
1011

1112
classFileextendsBlob{
1213
constructor(fileBits,fileName,options={}){
@@ -280,7 +281,7 @@ function processBlobParts (parts, options) {
280281
}
281282

282283
// 3. Append the result of UTF-8 encoding s to bytes.
283-
bytes.push(newTextEncoder().encode(s))
284+
bytes.push(encoder.encode(s))
284285
}elseif(
285286
types.isAnyArrayBuffer(element)||
286287
types.isTypedArray(element)

0 commit comments

Comments
 (0)