@libp2p/http-utils 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +2 -2
- package/dist/src/stream-to-socket.d.ts +2 -0
- package/dist/src/stream-to-socket.d.ts.map +1 -1
- package/dist/src/stream-to-socket.js +2 -0
- package/dist/src/stream-to-socket.js.map +1 -1
- package/package.json +1 -1
- package/src/stream-to-socket.ts +2 -0
package/dist/index.min.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
(?:${ue}:){1}(?:(?::${ue}){0,4}:${Ve}|(?::${ue}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
12
12
|
(?::(?:(?::${ue}){0,5}:${Ve}|(?::${ue}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
13
13
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
14
|
-
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Nm=new RegExp(`(?:^${Ve}$)|(?:^${Ni}$)`),Om=new RegExp(`^${Ve}$`),Pm=new RegExp(`^${Ni}$`),ca=t=>t&&t.exact?Nm:new RegExp(`(?:${Mt(t)}${Ve}${Mt(t)})|(?:${Mt(t)}${Ni}${Mt(t)})`,"g");ca.v4=t=>t&&t.exact?Om:new RegExp(`${Mt(t)}${Ve}${Mt(t)}`,"g");ca.v6=t=>t&&t.exact?Pm:new RegExp(`${Mt(t)}${Ni}${Mt(t)}`,"g");var ua=ca;function fa(t){let e=(...r)=>t(...r);return Object.defineProperty(e,"name",{value:`functionTimeout(${t.name||"<anonymous>"})`,configurable:!0}),e}function pl(){return!1}var{toString:Um}=Object.prototype;function la(t){return Um.call(t)==="[object RegExp]"}var yl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function da(t,e={}){if(!la(t))throw new TypeError("Expected a RegExp instance");let r=Object.keys(yl).map(i=>(typeof e[i]=="boolean"?e[i]:t[i])?yl[i]:"").join(""),n=new RegExp(e.source||t.source,r);return n.lastIndex=typeof e.lastIndex=="number"?e.lastIndex:t.lastIndex,n}function ha(t,e,{timeout:r}={}){try{return fa(()=>da(t).test(e),{timeout:r})()}catch(n){if(pl(n))return!1;throw n}}var Mm=15,km=45,bl={timeout:400};function pa(t){return t.length>km?!1:ha(ua.v6({exact:!0}),t,bl)}function ml(t){return t.length>Mm?!1:ha(ua.v4({exact:!0}),t,bl)}var wl={http:"80",https:"443",ws:"80",wss:"443"},qm=["http","https","ws","wss"];function gl(t,e){e=e??{};let r=e.defaultDnsType??"dns",{scheme:n,hostname:i,port:o,path:s}=Fm(t),a=[$m(i,r),Hm(o,n),Km(n)];s!=null&&a.push(Vm(s));let c="/"+a.filter(u=>!!u).reduce((u,l)=>u.concat(l),[]).join("/");return Ut(c)}function Fm(t){let[e]=t.split(":");qm.includes(e)||(t="http"+t.substring(e.length));let{protocol:r,hostname:n,port:i,pathname:o,search:s}=new URL(t);if(i==null||i===""){let c=Wm(e);c!=null&&(i=c),c==null&&r==="http:"&&(i="80")}let a;return o!=null&&o!==""&&o!=="/"&&(o.startsWith("/")&&(o=o.substring(1)),a=o),s!=null&&s!==""&&(a=a??"",a+=s),{scheme:e,hostname:n,port:i,path:a}}function $m(t,e){if(!(t==null||t==="")){if(ml(t))return["ip4",t];if(pa(t))return["ip6",t];if(t[0]==="["){let r=t.substring(1,t.length-1);if(pa(r))return["ip6",r]}return[e,t]}}function Hm(t,e){if(!(t==null||t===""))return e==="udp"?["udp",t]:["tcp",t]}function Km(t){if(t.match(/^tcp$|^udp$/)==null)return t==="https"?["/tls/http"]:t==="wss"?["/tls/ws"]:[t]}function Vm(t){if(!(t==null||t===""))return["http-path",encodeURIComponent(t)]}function Wm(t){if(!(t==null||t===""||wl[t]==null))return wl[t]}function xl(t){if(t!=null){if(typeof t[Symbol.iterator]=="function")return t[Symbol.iterator]();if(typeof t[Symbol.asyncIterator]=="function")return t[Symbol.asyncIterator]();if(typeof t.next=="function")return t}throw new Error("argument is not an iterator or iterable")}function ya(t,e={}){let r=xl(t),n={_cancelled:!1,async start(){this._cancelled=!1},async pull(i){try{let{value:o,done:s}=await r.next();if(this._cancelled)return;if(s===!0){i.close();return}i.enqueue(o)}catch(o){i.error(o)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(n,e)}var jm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),El=tn({name:"sha-1",code:17,encode:jm("SHA-1")});var Oi=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function Sl(t,e,r,n){let i=new Oi(n?.errorMessage);n?.errorCode!=null&&(i.code=n.errorCode);let o=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(i):new Promise((s,a)=>{function c(){ma(r,"abort",f),ma(t,e,u),ma(t,o,l)}let u=h=>{try{if(n?.filter?.(h)===!1)return}catch(d){c(),a(d);return}c(),s(h)},l=h=>{if(c(),h instanceof Error){a(h);return}a(h.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{c(),a(i)};ba(r,"abort",f),ba(t,e,u),ba(t,o,l)})}function ba(t,e,r){t!=null&&(_l(t)?t.addEventListener(e,r):t.addListener(e,r))}function ma(t,e,r){t!=null&&(_l(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function _l(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var vn=class extends globalThis.Request{constructor(e,r={}){let n=r.method??"GET",i=Rn(r),o=r.body;wa(n,i)&&(r.method="UPGRADE"),super(e,r),Object.defineProperties(this,{body:{value:o,writable:!1},method:{value:n,writable:!1},headers:{value:i,writable:!1}})}};var ga={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a Teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"};var xa=class extends globalThis.Response{constructor(e,r={}){let n=Rn(r),i=r.status??200;(i<200||i>599)&&(r.status=200),super(e,r),Object.defineProperties(this,{status:{value:i,writable:!1},statusText:{value:ga[i],writable:!1},headers:{value:n,writable:!1}})}};var t0=d0(Jp(),1),e0=2147483647,go=class extends t0.Duplex{autoSelectFamilyAttemptedAddresses=[];connecting=!1;pending=!1;remoteAddress;bytesRead;bytesWritten;timeout=e0;allowHalfOpen;#t;#r;#e;constructor(...e){super(),this.bytesRead=0,this.bytesWritten=0,this.allowHalfOpen=!0,this.remoteAddress="",e.length===2?(this.gotStream({stream:e[0],connection:e[1]}),this.#t=Promise.resolve(e[0])):this.#t=e[0].then(this.gotStream.bind(this),r=>{throw this.emit("error",r),r})}gotStream({stream:e,connection:r}){return this.#e=e.log.newScope("libp2p-socket"),this.remoteAddress=r.remoteAddr.toString(),e.addEventListener("message",n=>{this.push(n.data.subarray())}),e.addEventListener("close",n=>{n.error!=null?this.destroy(n.error):this.push(null)}),e.pause(),this.emit("connect"),e}getStream(e){if(this.#r!=null){e(this.#r);return}this.#t.then(r=>{this.#r=r,e(r)},r=>{this.emit("error",r)})}destroy(e){return super.destroy(e)}_write(e,r,n){this.#e?.("write %d bytes",e.byteLength),this.bytesWritten+=e.byteLength,this.getStream(i=>{i.send(e)?n():i.onDrain().then(()=>{n()},o=>{n(o)})})}_read(e){this.#e?.("asked to read %d bytes",e),this.getStream(r=>{r.resume()})}_destroy(e,r){this.#e?.("destroy with %d bytes buffered - %e",this.bufferSize,e),this.getStream(n=>{e!=null?(n.abort(e),r()):n.close().then(()=>{r()}).catch(i=>{n.abort(i),r(i)})})}_final(e){this.#e?.("final"),this.getStream(r=>{r.close().then(()=>{e()}).catch(n=>{r.abort(n),e(n)})})}get readyState(){return this.#r?.status==="closed"?"closed":this.#r?.writeStatus==="closed"||this.#r?.writeStatus==="closing"?"readOnly":this.#r?.readStatus==="closed"||this.#r?.readStatus==="closing"?"writeOnly":"open"}get bufferSize(){return this.writableLength}destroySoon(){this.#e?.("destroySoon with %d bytes buffered",this.bufferSize),this.destroy()}connect(...e){return this.#e?.("connect %o",e),this}setEncoding(e){return this.#e?.("setEncoding %s",e),this}resetAndDestroy(){return this.#e?.("resetAndDestroy"),this.getStream(e=>{e.abort(new Error("Libp2pSocket.resetAndDestroy"))}),this}setTimeout(e,r){return this.#e?.("setTimeout %d",e),r!=null&&this.addListener("timeout",r),this.timeout=e===0?e0:e,this}setNoDelay(e){return this.#e?.("setNoDelay %b",e),this}setKeepAlive(e,r){return this.#e?.("setKeepAlive %b %d",e,r),this}address(){return this.#e?.("address"),{}}unref(){return this.#e?.("unref"),this}ref(){return this.#e?.("ref"),this}write(e,r,n){return super.write(e,r,n)}};function Q2(t,e){return new go(t,e)}var J2=["dns","dns4","dns6","dnsaddr"];function eS(t,e){if(t instanceof URL)return t;let r=i0(t,e),{httpPath:n}=o0(t);return new URL(`http://${r}${n}`)}function tS(t){return t instanceof Uint8Array?t:t instanceof DataView?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t,0,t.byteLength)}function rS(t,e){let r={method:t.method,headers:t.headers};if((r.method!=="GET"||t.upgrade)&&r.method!=="HEAD"){let n=e;t.upgrade||(n=cS(e,t.headers.get("content-length"))),r.body=ya(n),r.duplex="half"}return new vn(s0(t).toString(),r)}async function nS(t,e){if(e.send(ce([`HTTP/1.1 ${t.status} ${t.statusText}`,...n0(t.headers),"",""].join(`\r
|
|
14
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Nm=new RegExp(`(?:^${Ve}$)|(?:^${Ni}$)`),Om=new RegExp(`^${Ve}$`),Pm=new RegExp(`^${Ni}$`),ca=t=>t&&t.exact?Nm:new RegExp(`(?:${Mt(t)}${Ve}${Mt(t)})|(?:${Mt(t)}${Ni}${Mt(t)})`,"g");ca.v4=t=>t&&t.exact?Om:new RegExp(`${Mt(t)}${Ve}${Mt(t)}`,"g");ca.v6=t=>t&&t.exact?Pm:new RegExp(`${Mt(t)}${Ni}${Mt(t)}`,"g");var ua=ca;function fa(t){let e=(...r)=>t(...r);return Object.defineProperty(e,"name",{value:`functionTimeout(${t.name||"<anonymous>"})`,configurable:!0}),e}function pl(){return!1}var{toString:Um}=Object.prototype;function la(t){return Um.call(t)==="[object RegExp]"}var yl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function da(t,e={}){if(!la(t))throw new TypeError("Expected a RegExp instance");let r=Object.keys(yl).map(i=>(typeof e[i]=="boolean"?e[i]:t[i])?yl[i]:"").join(""),n=new RegExp(e.source||t.source,r);return n.lastIndex=typeof e.lastIndex=="number"?e.lastIndex:t.lastIndex,n}function ha(t,e,{timeout:r}={}){try{return fa(()=>da(t).test(e),{timeout:r})()}catch(n){if(pl(n))return!1;throw n}}var Mm=15,km=45,bl={timeout:400};function pa(t){return t.length>km?!1:ha(ua.v6({exact:!0}),t,bl)}function ml(t){return t.length>Mm?!1:ha(ua.v4({exact:!0}),t,bl)}var wl={http:"80",https:"443",ws:"80",wss:"443"},qm=["http","https","ws","wss"];function gl(t,e){e=e??{};let r=e.defaultDnsType??"dns",{scheme:n,hostname:i,port:o,path:s}=Fm(t),a=[$m(i,r),Hm(o,n),Km(n)];s!=null&&a.push(Vm(s));let c="/"+a.filter(u=>!!u).reduce((u,l)=>u.concat(l),[]).join("/");return Ut(c)}function Fm(t){let[e]=t.split(":");qm.includes(e)||(t="http"+t.substring(e.length));let{protocol:r,hostname:n,port:i,pathname:o,search:s}=new URL(t);if(i==null||i===""){let c=Wm(e);c!=null&&(i=c),c==null&&r==="http:"&&(i="80")}let a;return o!=null&&o!==""&&o!=="/"&&(o.startsWith("/")&&(o=o.substring(1)),a=o),s!=null&&s!==""&&(a=a??"",a+=s),{scheme:e,hostname:n,port:i,path:a}}function $m(t,e){if(!(t==null||t==="")){if(ml(t))return["ip4",t];if(pa(t))return["ip6",t];if(t[0]==="["){let r=t.substring(1,t.length-1);if(pa(r))return["ip6",r]}return[e,t]}}function Hm(t,e){if(!(t==null||t===""))return e==="udp"?["udp",t]:["tcp",t]}function Km(t){if(t.match(/^tcp$|^udp$/)==null)return t==="https"?["/tls/http"]:t==="wss"?["/tls/ws"]:[t]}function Vm(t){if(!(t==null||t===""))return["http-path",encodeURIComponent(t)]}function Wm(t){if(!(t==null||t===""||wl[t]==null))return wl[t]}function xl(t){if(t!=null){if(typeof t[Symbol.iterator]=="function")return t[Symbol.iterator]();if(typeof t[Symbol.asyncIterator]=="function")return t[Symbol.asyncIterator]();if(typeof t.next=="function")return t}throw new Error("argument is not an iterator or iterable")}function ya(t,e={}){let r=xl(t),n={_cancelled:!1,async start(){this._cancelled=!1},async pull(i){try{let{value:o,done:s}=await r.next();if(this._cancelled)return;if(s===!0){i.close();return}i.enqueue(o)}catch(o){i.error(o)}},cancel(){this._cancelled=!0}};return new globalThis.ReadableStream(n,e)}var jm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),El=tn({name:"sha-1",code:17,encode:jm("SHA-1")});var Oi=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function Sl(t,e,r,n){let i=new Oi(n?.errorMessage);n?.errorCode!=null&&(i.code=n.errorCode);let o=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(i):new Promise((s,a)=>{function c(){ma(r,"abort",f),ma(t,e,u),ma(t,o,l)}let u=h=>{try{if(n?.filter?.(h)===!1)return}catch(d){c(),a(d);return}c(),s(h)},l=h=>{if(c(),h instanceof Error){a(h);return}a(h.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{c(),a(i)};ba(r,"abort",f),ba(t,e,u),ba(t,o,l)})}function ba(t,e,r){t!=null&&(_l(t)?t.addEventListener(e,r):t.addListener(e,r))}function ma(t,e,r){t!=null&&(_l(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function _l(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var vn=class extends globalThis.Request{constructor(e,r={}){let n=r.method??"GET",i=Rn(r),o=r.body;wa(n,i)&&(r.method="UPGRADE"),super(e,r),Object.defineProperties(this,{body:{value:o,writable:!1},method:{value:n,writable:!1},headers:{value:i,writable:!1}})}};var ga={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a Teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"};var xa=class extends globalThis.Response{constructor(e,r={}){let n=Rn(r),i=r.status??200;(i<200||i>599)&&(r.status=200),super(e,r),Object.defineProperties(this,{status:{value:i,writable:!1},statusText:{value:ga[i],writable:!1},headers:{value:n,writable:!1}})}};var t0=d0(Jp(),1),e0=2147483647,go=class extends t0.Duplex{autoSelectFamilyAttemptedAddresses=[];connecting=!1;pending=!1;remoteAddress;bytesRead;bytesWritten;timeout=e0;allowHalfOpen;remoteFamily;remotePort;#t;#r;#e;constructor(...e){super(),this.bytesRead=0,this.bytesWritten=0,this.allowHalfOpen=!0,this.remoteAddress="",e.length===2?(this.gotStream({stream:e[0],connection:e[1]}),this.#t=Promise.resolve(e[0])):this.#t=e[0].then(this.gotStream.bind(this),r=>{throw this.emit("error",r),r})}gotStream({stream:e,connection:r}){return this.#e=e.log.newScope("libp2p-socket"),this.remoteAddress=r.remoteAddr.toString(),e.addEventListener("message",n=>{this.push(n.data.subarray())}),e.addEventListener("close",n=>{n.error!=null?this.destroy(n.error):this.push(null)}),e.pause(),this.emit("connect"),e}getStream(e){if(this.#r!=null){e(this.#r);return}this.#t.then(r=>{this.#r=r,e(r)},r=>{this.emit("error",r)})}destroy(e){return super.destroy(e)}_write(e,r,n){this.#e?.("write %d bytes",e.byteLength),this.bytesWritten+=e.byteLength,this.getStream(i=>{i.send(e)?n():i.onDrain().then(()=>{n()},o=>{n(o)})})}_read(e){this.#e?.("asked to read %d bytes",e),this.getStream(r=>{r.resume()})}_destroy(e,r){this.#e?.("destroy with %d bytes buffered - %e",this.bufferSize,e),this.getStream(n=>{e!=null?(n.abort(e),r()):n.close().then(()=>{r()}).catch(i=>{n.abort(i),r(i)})})}_final(e){this.#e?.("final"),this.getStream(r=>{r.close().then(()=>{e()}).catch(n=>{r.abort(n),e(n)})})}get readyState(){return this.#r?.status==="closed"?"closed":this.#r?.writeStatus==="closed"||this.#r?.writeStatus==="closing"?"readOnly":this.#r?.readStatus==="closed"||this.#r?.readStatus==="closing"?"writeOnly":"open"}get bufferSize(){return this.writableLength}destroySoon(){this.#e?.("destroySoon with %d bytes buffered",this.bufferSize),this.destroy()}connect(...e){return this.#e?.("connect %o",e),this}setEncoding(e){return this.#e?.("setEncoding %s",e),this}resetAndDestroy(){return this.#e?.("resetAndDestroy"),this.getStream(e=>{e.abort(new Error("Libp2pSocket.resetAndDestroy"))}),this}setTimeout(e,r){return this.#e?.("setTimeout %d",e),r!=null&&this.addListener("timeout",r),this.timeout=e===0?e0:e,this}setNoDelay(e){return this.#e?.("setNoDelay %b",e),this}setKeepAlive(e,r){return this.#e?.("setKeepAlive %b %d",e,r),this}address(){return this.#e?.("address"),{}}unref(){return this.#e?.("unref"),this}ref(){return this.#e?.("ref"),this}write(e,r,n){return super.write(e,r,n)}};function Q2(t,e){return new go(t,e)}var J2=["dns","dns4","dns6","dnsaddr"];function eS(t,e){if(t instanceof URL)return t;let r=i0(t,e),{httpPath:n}=o0(t);return new URL(`http://${r}${n}`)}function tS(t){return t instanceof Uint8Array?t:t instanceof DataView?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t,0,t.byteLength)}function rS(t,e){let r={method:t.method,headers:t.headers};if((r.method!=="GET"||t.upgrade)&&r.method!=="HEAD"){let n=e;t.upgrade||(n=cS(e,t.headers.get("content-length"))),r.body=ya(n),r.duplex="half"}return new vn(s0(t).toString(),r)}async function nS(t,e){if(e.send(ce([`HTTP/1.1 ${t.status} ${t.statusText}`,...n0(t.headers),"",""].join(`\r
|
|
15
15
|
`))),t.body==null){await e.close().catch(n=>{e.abort(n)});return}let r=t.body.getReader();for(;;){let n=await r.read();if(n.value!=null&&(e.send(n.value)||await e.onDrain()),n.done)break}await e.close().catch(n=>{e.abort(n)})}var iS=ce(["HTTP/1.1 404 Not Found","Connection: close","",""].join(`\r
|
|
16
16
|
`)),oS=ce(["HTTP/1.1 400 Bad Request","Connection: close","",""].join(`\r
|
|
17
17
|
`)),sS=ce(["HTTP/1.1 500 Internal Server Error","Connection: close","",""].join(`\r
|