UNPKG

@zhengxs/http

Version:

A lightweight cross-platform http request library

3 lines (2 loc) 1.51 kB
"use strict";const o=require("node:fs");require("node:http");const l=require("node:stream"),u=require("node:stream/web"),i=require("agentkeepalive"),d=require("form-data-encoder"),g=require("../MultipartBody.cjs"),c=require("../registry.cjs");class h extends globalThis.Blob{static[Symbol.hasInstance](e){return e instanceof Blob&&e[Symbol.toStringTag]==="File"&&typeof e.name=="string"}#e;#t=0;constructor(e,r,n={}){if(super(e,n),arguments.length<2)throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);this.#e=String(r);const s=n.lastModified===void 0?Date.now():Number(n.lastModified);Number.isNaN(s)||(this.#t=s)}get name(){return this.#e}get webkitRelativePath(){return""}get lastModified(){return this.#t}get[Symbol.toStringTag](){return"File"}}const b=new i({keepAlive:!0,timeout:5*60*1e3}),m=new i.HttpsAgent({keepAlive:!0,timeout:5*60*1e3});async function f(t,e){const r=new d.FormDataEncoder(t),n=l.Readable.from(r),s=new g.MultipartBody(n),a={...e.headers,...r.headers,"Content-Length":r.contentLength};return{...e,body:s,headers:a}}function p(){return{kind:"node",getMultipartRequestOptions:f,getDefaultAgent:t=>t.startsWith("https")?m:b,isFsReadStream:t=>t instanceof o.ReadStream,fetch:globalThis.fetch,Request:globalThis.Request,Response:globalThis.Response,Headers:globalThis.Headers,FormData:globalThis.FormData,Blob:globalThis.Blob,ReadableStream:u.ReadableStream,File:globalThis.File||h}}c.setShims(p()); //# sourceMappingURL=node.cjs.map