httpquick 1.1.9 → 1.1.11

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.
@@ -1,8 +1,6 @@
1
1
  class u {
2
2
  // 默认请求
3
3
  config = {};
4
- // 请求编号 debug使用的
5
- requestId = 0;
6
4
  // 请求中间件
7
5
  middlewares = [];
8
6
  // 构造函数
@@ -20,9 +18,8 @@ class u {
20
18
  // 获取默认请求结构
21
19
  getDefaultRequest() {
22
20
  return {
23
- id: 0,
24
- baseUrl: "",
25
21
  method: "GET",
22
+ baseUrl: "",
26
23
  url: "/",
27
24
  headers: {},
28
25
  query: null,
@@ -49,11 +46,11 @@ class u {
49
46
  }
50
47
  // 填充请求行
51
48
  fillUrl(e) {
52
- e.fullUrl = (/^https?:\/\//.test(e.url) ? e.url : e.baseUrl + e.url) + (e.query ? "?" + this.obj2query(e.query) : "");
49
+ e.fullUrl = (/^https?:\/\//.test(e.url) ? e.url : e.baseUrl + e.url) + (e.query && Object.keys(e.query).length ? "?" + this.obj2query(e.query) : "");
53
50
  }
54
51
  // 填充请求头
55
52
  fillHeaders(e) {
56
- e.responseType == "text" && e.dataType == "json" && (e.headers.Accept = "application/json");
53
+ e.responseType == "text" && e.dataType == "json" ? e.headers.Accept = "application/json; charset=utf-8" : e.responseType == "text" && e.dataType == "xml" ? e.headers.Accept = "application/xml; charset=utf-8" : e.responseType == "text" ? e.headers.Accept = "text/plain; charset=utf-8" : (e.responseType == "arraybuffer" || e.responseType == "blob") && (e.headers.Accept = "application/octet-stream");
57
54
  }
58
55
  // 填充请求体
59
56
  fillBody(e) {
@@ -0,0 +1 @@
1
+ "use strict";class d{config={};middlewares=[];constructor(e={}){Object.assign(this.config,e)}updateConfig(e={}){Object.assign(this.config,e)}addMiddleware(e){this.middlewares.push(e.bind(this))}getDefaultRequest(){return{method:"GET",baseUrl:"",url:"/",headers:{},query:null,json:null,body:null,responseType:"text",dataType:"json",timeout:6e4,fullUrl:""}}getDefaultResponse(){return{status:-1,statusText:"NONE",headers:{},body:null}}obj2query(e){return typeof URLSearchParams<"u"?new URLSearchParams(e).toString():Object.entries(e).map(([t,s])=>encodeURIComponent(t)+"="+encodeURIComponent(s)).join("&")}fillUrl(e){e.fullUrl=(/^https?:\/\//.test(e.url)?e.url:e.baseUrl+e.url)+(e.query&&Object.keys(e.query).length?"?"+this.obj2query(e.query):"")}fillHeaders(e){e.responseType=="text"&&e.dataType=="json"?e.headers.Accept="application/json; charset=utf-8":e.responseType=="text"&&e.dataType=="xml"?e.headers.Accept="application/xml; charset=utf-8":e.responseType=="text"?e.headers.Accept="text/plain; charset=utf-8":(e.responseType=="arraybuffer"||e.responseType=="blob")&&(e.headers.Accept="application/octet-stream")}fillBody(e){(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(process?.versions?.node||"0.0.0")!=="0.0.0"&&(e.headers["content-type"]=e.body.getContentType(),e.body=e.body.toStream()):e.body!==null&&typeof URLSearchParams<"u"&&e.body instanceof URLSearchParams?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.map(t=>encodeURIComponent(t.key)+"="+encodeURIComponent(t.val)).join("&")):e.body!==null&&Object.isObject(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json; charset=utf-8",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body="")))}get(e){return this.request({...e,method:"GET"})}post(e){return this.request({...e,method:"POST"})}put(e){return this.request({...e,method:"PUT"})}del(e){return this.request({...e,method:"DELETE"})}upload(e){return new Error("unreachable")}download(e){return new Error("unreachable")}onTimeoutError=function(e,t,s=null){console.error("http timeout",s),t.status=-4,t.statusText="TIMEOUT",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-1,errmsg:(t.response.status??t.status)+", 网络请求超时!"}:t.body="网络请求超时!"};onNetworkError(e,t,s=null){console.error("http error",s),t.status=-1,t.statusText="NETWORK FAIL",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-2,errmsg:(t.response.status??t.status)+", 网络请求错误!"}:t.body="网络请求错误!"}async request(e){const t=Object.assign(this.getDefaultRequest(),this.config,e);let s=this.getDefaultResponse();t.method=t.method.toUpperCase(),Object.defineProperties(t,{response:{value:s,enumerable:!1,configurable:!0,writable:!0}}),Object.defineProperties(s,{request:{value:t,enumerable:!1,configurable:!0,writable:!0},response:{value:null,enumerable:!1,configurable:!0,writable:!0},parent:{value:null,enumerable:!1,configurable:!0,writable:!0}}),this.fillUrl(t),this.fillHeaders(t),this.fillBody(t);let n=async(o,a)=>await this.send(o,a);for(let o=this.middlewares.length-1;o>=0;o--){const a=n,l=this.middlewares[o].bind(this);n=async(i,r)=>await l(i,r,a)}return await n(t,s),s}send(e,t){}install(e,t={}){e.config.globalProperties.$http=this;for(const s in t)this[s]=t[s]}globalMethods(){globalThis.httpGet=this.get.bind(this),globalThis.httpPost=this.post.bind(this),globalThis.httpPut=this.put.bind(this),globalThis.httpDelete=this.del.bind(this),globalThis.httpUpload=this.upload.bind(this),globalThis.httpDownload=this.download.bind(this)}}exports.HttpQuickBase=d;
package/dist/ajax.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as a } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as a } from "./HttpQuickBase-BwWho-sN.js";
2
2
  class l extends a {
3
3
  // 发送请求
4
4
  send(t, o) {
package/dist/fetch.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as l } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as l } from "./HttpQuickBase-BwWho-sN.js";
2
2
  class h extends l {
3
3
  // 发送请求
4
4
  async send(t, o) {
package/dist/fibjs.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./HttpQuickBase-Bebs7K6z.cjs"),d=require("http"),i=require("util");class n extends o.HttpQuickBase{send(e,a){try{const t=d.request(e.method,e.fullUrl,{headers:e.headers,body:e.body||""});a.status=t.statusCode,a.statusText=t.statusMessage;for(let s of t.headers.keys()){const r=t.headers.all(s);s=s.toLowerCase();for(const u of r)a.headers[s]=u}try{e.responseType=="text"&&e.dataType=="json"?a.body=Buffer.isBuffer(t.data)?JSON.parse(t.data.toString("utf8")):typeof t.data=="string"?JSON.parse(t.data):t.data:e.responseType=="text"?a.body=Buffer.isBuffer(t.data)?t.data.toString("utf8"):(typeof t.data=="string",t.data):a.body=t.data}catch{a.body=t.data}}catch(t){return this.onTimeoutError(e,a,t)}}request(e){return i.sync(async a=>await super.request(a))(e)}}exports.HttpQuickBase=o.HttpQuickBase;exports.HttpQuick=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./HttpQuickBase-MzEqICTi.cjs"),d=require("http"),i=require("util");class n extends o.HttpQuickBase{send(e,a){try{const t=d.request(e.method,e.fullUrl,{headers:e.headers,body:e.body||""});a.status=t.statusCode,a.statusText=t.statusMessage;for(let s of t.headers.keys()){const r=t.headers.all(s);s=s.toLowerCase();for(const u of r)a.headers[s]=u}try{e.responseType=="text"&&e.dataType=="json"?a.body=Buffer.isBuffer(t.data)?JSON.parse(t.data.toString("utf8")):typeof t.data=="string"?JSON.parse(t.data):t.data:e.responseType=="text"?a.body=Buffer.isBuffer(t.data)?t.data.toString("utf8"):(typeof t.data=="string",t.data):a.body=t.data}catch{a.body=t.data}}catch(t){return this.onTimeoutError(e,a,t)}}request(e){return i.sync(async a=>await super.request(a))(e)}}exports.HttpQuickBase=o.HttpQuickBase;exports.HttpQuick=n;
package/dist/fibjs.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as d } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as d } from "./HttpQuickBase-BwWho-sN.js";
2
2
  import u from "http";
3
3
  import f from "util";
4
4
  class c extends d {
@@ -1,2 +1,2 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.httpquick={}))})(this,(function(i){"use strict";class a{config={};requestId=0;middlewares=[];constructor(e={}){Object.assign(this.config,e)}updateConfig(e={}){Object.assign(this.config,e)}addMiddleware(e){this.middlewares.push(e.bind(this))}getDefaultRequest(){return{id:0,baseUrl:"",method:"GET",url:"/",headers:{},query:null,json:null,body:null,responseType:"text",dataType:"json",timeout:6e4,fullUrl:""}}getDefaultResponse(){return{status:-1,statusText:"NONE",headers:{},body:null}}obj2query(e){return typeof URLSearchParams<"u"?new URLSearchParams(e).toString():Object.entries(e).map(([t,o])=>encodeURIComponent(t)+"="+encodeURIComponent(o)).join("&")}fillUrl(e){e.fullUrl=(/^https?:\/\//.test(e.url)?e.url:e.baseUrl+e.url)+(e.query?"?"+this.obj2query(e.query):"")}fillHeaders(e){e.responseType=="text"&&e.dataType=="json"&&(e.headers.Accept="application/json")}fillBody(e){(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(process?.versions?.node||"0.0.0")!=="0.0.0"&&(e.headers["content-type"]=e.body.getContentType(),e.body=e.body.toStream()):e.body!==null&&typeof URLSearchParams<"u"&&e.body instanceof URLSearchParams?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.map(t=>encodeURIComponent(t.key)+"="+encodeURIComponent(t.val)).join("&")):e.body!==null&&Object.isObject(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json; charset=utf-8",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body="")))}get(e){return this.request({...e,method:"GET"})}post(e){return this.request({...e,method:"POST"})}put(e){return this.request({...e,method:"PUT"})}del(e){return this.request({...e,method:"DELETE"})}upload(e){return new Error("unreachable")}download(e){return new Error("unreachable")}onTimeoutError=function(e,t,o=null){console.error("http timeout",o),t.status=-4,t.statusText="TIMEOUT",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-1,errmsg:(t.response.status??t.status)+", 网络请求超时!"}:t.body="网络请求超时!"};onNetworkError(e,t,o=null){console.error("http error",o),t.status=-1,t.statusText="NETWORK FAIL",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-2,errmsg:(t.response.status??t.status)+", 网络请求错误!"}:t.body="网络请求错误!"}async request(e){const t=Object.assign(this.getDefaultRequest(),this.config,e);let o=this.getDefaultResponse();t.method=t.method.toUpperCase(),Object.defineProperties(t,{response:{value:o,enumerable:!1,configurable:!0,writable:!0}}),Object.defineProperties(o,{request:{value:t,enumerable:!1,configurable:!0,writable:!0},response:{value:null,enumerable:!1,configurable:!0,writable:!0},parent:{value:null,enumerable:!1,configurable:!0,writable:!0}}),this.fillUrl(t),this.fillHeaders(t),this.fillBody(t);let l=async(s,n)=>await this.send(s,n);for(let s=this.middlewares.length-1;s>=0;s--){const n=l,r=this.middlewares[s].bind(this);l=async(p,h)=>await r(p,h,n)}return await l(t,o),o}send(e,t){}install(e,t={}){e.config.globalProperties.$http=this;for(const o in t)this[o]=t[o]}globalMethods(){globalThis.httpGet=this.get.bind(this),globalThis.httpPost=this.post.bind(this),globalThis.httpPut=this.put.bind(this),globalThis.httpDelete=this.del.bind(this),globalThis.httpUpload=this.upload.bind(this),globalThis.httpDownload=this.download.bind(this)}}class d extends a{send(e,t){let o=null,l=new Promise(n=>o=n);const s=t.response=new XMLHttpRequest;s.open(e.method,e.fullUrl,!0),s.timeout=e.timeout,s.withCredentials=e.withCredentials||!1,s.responseType=e.responseType;for(const[n,r]of Object.entries(e.headers))s.setRequestHeader(n,r);return s.ontimeout=n=>{this.onTimeoutError(e,t,n),o()},s.onerror=n=>{this.onNetworkError(e,t,n),o()},e.onprocess&&s.upload.addEventListener("progress",e.onprocess),s.onreadystatechange=()=>{if(!(s.readyState!==4||s.status==0)){t.status=s.status,t.statusText=s.statusText,t.headers=Object.fromEntries(s.getAllResponseHeaders().trim().replaceAll("\r","").split(`
2
- `).map(n=>[decodeURIComponent(n.substring(0,n.indexOf(": ")).toLowerCase()),decodeURIComponent(n.substring(n.indexOf(": ")+2))]));try{e.responseType=="text"&&e.dataType=="json"?t.body=JSON.parse(s.responseText):e.responseType=="text"?t.body=s.responseText:t.body=s.response}catch{t.body=s.response}o()}},e.method=="POST"||e.method=="PUT"?s.send(e.body):s.send(),l}}i.HttpQuick=d,i.HttpQuickBase=a,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.httpquick={}))})(this,(function(a){"use strict";class i{config={};middlewares=[];constructor(e={}){Object.assign(this.config,e)}updateConfig(e={}){Object.assign(this.config,e)}addMiddleware(e){this.middlewares.push(e.bind(this))}getDefaultRequest(){return{method:"GET",baseUrl:"",url:"/",headers:{},query:null,json:null,body:null,responseType:"text",dataType:"json",timeout:6e4,fullUrl:""}}getDefaultResponse(){return{status:-1,statusText:"NONE",headers:{},body:null}}obj2query(e){return typeof URLSearchParams<"u"?new URLSearchParams(e).toString():Object.entries(e).map(([t,o])=>encodeURIComponent(t)+"="+encodeURIComponent(o)).join("&")}fillUrl(e){e.fullUrl=(/^https?:\/\//.test(e.url)?e.url:e.baseUrl+e.url)+(e.query&&Object.keys(e.query).length?"?"+this.obj2query(e.query):"")}fillHeaders(e){e.responseType=="text"&&e.dataType=="json"?e.headers.Accept="application/json; charset=utf-8":e.responseType=="text"&&e.dataType=="xml"?e.headers.Accept="application/xml; charset=utf-8":e.responseType=="text"?e.headers.Accept="text/plain; charset=utf-8":(e.responseType=="arraybuffer"||e.responseType=="blob")&&(e.headers.Accept="application/octet-stream")}fillBody(e){(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(process?.versions?.node||"0.0.0")!=="0.0.0"&&(e.headers["content-type"]=e.body.getContentType(),e.body=e.body.toStream()):e.body!==null&&typeof URLSearchParams<"u"&&e.body instanceof URLSearchParams?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.map(t=>encodeURIComponent(t.key)+"="+encodeURIComponent(t.val)).join("&")):e.body!==null&&Object.isObject(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json; charset=utf-8",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body="")))}get(e){return this.request({...e,method:"GET"})}post(e){return this.request({...e,method:"POST"})}put(e){return this.request({...e,method:"PUT"})}del(e){return this.request({...e,method:"DELETE"})}upload(e){return new Error("unreachable")}download(e){return new Error("unreachable")}onTimeoutError=function(e,t,o=null){console.error("http timeout",o),t.status=-4,t.statusText="TIMEOUT",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-1,errmsg:(t.response.status??t.status)+", 网络请求超时!"}:t.body="网络请求超时!"};onNetworkError(e,t,o=null){console.error("http error",o),t.status=-1,t.statusText="NETWORK FAIL",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-2,errmsg:(t.response.status??t.status)+", 网络请求错误!"}:t.body="网络请求错误!"}async request(e){const t=Object.assign(this.getDefaultRequest(),this.config,e);let o=this.getDefaultResponse();t.method=t.method.toUpperCase(),Object.defineProperties(t,{response:{value:o,enumerable:!1,configurable:!0,writable:!0}}),Object.defineProperties(o,{request:{value:t,enumerable:!1,configurable:!0,writable:!0},response:{value:null,enumerable:!1,configurable:!0,writable:!0},parent:{value:null,enumerable:!1,configurable:!0,writable:!0}}),this.fillUrl(t),this.fillHeaders(t),this.fillBody(t);let l=async(s,n)=>await this.send(s,n);for(let s=this.middlewares.length-1;s>=0;s--){const n=l,r=this.middlewares[s].bind(this);l=async(p,h)=>await r(p,h,n)}return await l(t,o),o}send(e,t){}install(e,t={}){e.config.globalProperties.$http=this;for(const o in t)this[o]=t[o]}globalMethods(){globalThis.httpGet=this.get.bind(this),globalThis.httpPost=this.post.bind(this),globalThis.httpPut=this.put.bind(this),globalThis.httpDelete=this.del.bind(this),globalThis.httpUpload=this.upload.bind(this),globalThis.httpDownload=this.download.bind(this)}}class d extends i{send(e,t){let o=null,l=new Promise(n=>o=n);const s=t.response=new XMLHttpRequest;s.open(e.method,e.fullUrl,!0),s.timeout=e.timeout,s.withCredentials=e.withCredentials||!1,s.responseType=e.responseType;for(const[n,r]of Object.entries(e.headers))s.setRequestHeader(n,r);return s.ontimeout=n=>{this.onTimeoutError(e,t,n),o()},s.onerror=n=>{this.onNetworkError(e,t,n),o()},e.onprocess&&s.upload.addEventListener("progress",e.onprocess),s.onreadystatechange=()=>{if(!(s.readyState!==4||s.status==0)){t.status=s.status,t.statusText=s.statusText,t.headers=Object.fromEntries(s.getAllResponseHeaders().trim().replaceAll("\r","").split(`
2
+ `).map(n=>[decodeURIComponent(n.substring(0,n.indexOf(": ")).toLowerCase()),decodeURIComponent(n.substring(n.indexOf(": ")+2))]));try{e.responseType=="text"&&e.dataType=="json"?t.body=JSON.parse(s.responseText):e.responseType=="text"?t.body=s.responseText:t.body=s.response}catch{t.body=s.response}o()}},e.method=="POST"||e.method=="PUT"?s.send(e.body):s.send(),l}}a.HttpQuick=d,a.HttpQuickBase=i,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/dist/node.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./HttpQuickBase-Bebs7K6z.cjs");class p extends r.HttpQuickBase{send(t,o){let n=null,a=new Promise(s=>n=s);const e=o.response=new XMLHttpRequest;e.open(t.method,t.fullUrl,!0),e.timeout=t.timeout,e.withCredentials=t.withCredentials||!1,e.responseType=t.responseType;for(const[s,i]of Object.entries(t.headers))e.setRequestHeader(s,i);return e.ontimeout=s=>{this.onTimeoutError(t,o,s),n()},e.onerror=s=>{this.onNetworkError(t,o,s),n()},t.onprocess&&e.upload.addEventListener("progress",t.onprocess),e.onreadystatechange=()=>{if(!(e.readyState!==4||e.status==0)){o.status=e.status,o.statusText=e.statusText,o.headers=Object.fromEntries(e.getAllResponseHeaders().trim().replaceAll("\r","").split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./HttpQuickBase-MzEqICTi.cjs");class p extends r.HttpQuickBase{send(t,o){let n=null,a=new Promise(s=>n=s);const e=o.response=new XMLHttpRequest;e.open(t.method,t.fullUrl,!0),e.timeout=t.timeout,e.withCredentials=t.withCredentials||!1,e.responseType=t.responseType;for(const[s,i]of Object.entries(t.headers))e.setRequestHeader(s,i);return e.ontimeout=s=>{this.onTimeoutError(t,o,s),n()},e.onerror=s=>{this.onNetworkError(t,o,s),n()},t.onprocess&&e.upload.addEventListener("progress",t.onprocess),e.onreadystatechange=()=>{if(!(e.readyState!==4||e.status==0)){o.status=e.status,o.statusText=e.statusText,o.headers=Object.fromEntries(e.getAllResponseHeaders().trim().replaceAll("\r","").split(`
2
2
  `).map(s=>[decodeURIComponent(s.substring(0,s.indexOf(": ")).toLowerCase()),decodeURIComponent(s.substring(s.indexOf(": ")+2))]));try{t.responseType=="text"&&t.dataType=="json"?o.body=JSON.parse(e.responseText):t.responseType=="text"?o.body=e.responseText:o.body=e.response}catch{o.body=e.response}n()}},t.method=="POST"||t.method=="PUT"?e.send(t.body):e.send(),a}}exports.HttpQuickBase=r.HttpQuickBase;exports.HttpQuick=p;
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as a } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as a } from "./HttpQuickBase-BwWho-sN.js";
2
2
  class l extends a {
3
3
  // 发送请求
4
4
  send(t, o) {
package/dist/uniapp.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as i } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as i } from "./HttpQuickBase-BwWho-sN.js";
2
2
  class u extends i {
3
3
  // 上传文件
4
4
  upload(e) {
package/dist/xcx.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as r } from "./HttpQuickBase-Bwjk70F3.js";
1
+ import { H as r } from "./HttpQuickBase-BwWho-sN.js";
2
2
  class u extends r {
3
3
  // 上传文件
4
4
  upload(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpquick",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "js http quick request",
5
5
  "author": "dotcoo <dotcoo@163.com> (http://blog.dotcoo.com)",
6
6
  "homepage": "https://github.com/dotcoo/httpquick#readme",
@@ -1 +0,0 @@
1
- "use strict";class d{config={};requestId=0;middlewares=[];constructor(e={}){Object.assign(this.config,e)}updateConfig(e={}){Object.assign(this.config,e)}addMiddleware(e){this.middlewares.push(e.bind(this))}getDefaultRequest(){return{id:0,baseUrl:"",method:"GET",url:"/",headers:{},query:null,json:null,body:null,responseType:"text",dataType:"json",timeout:6e4,fullUrl:""}}getDefaultResponse(){return{status:-1,statusText:"NONE",headers:{},body:null}}obj2query(e){return typeof URLSearchParams<"u"?new URLSearchParams(e).toString():Object.entries(e).map(([t,s])=>encodeURIComponent(t)+"="+encodeURIComponent(s)).join("&")}fillUrl(e){e.fullUrl=(/^https?:\/\//.test(e.url)?e.url:e.baseUrl+e.url)+(e.query?"?"+this.obj2query(e.query):"")}fillHeaders(e){e.responseType=="text"&&e.dataType=="json"&&(e.headers.Accept="application/json")}fillBody(e){(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(process?.versions?.node||"0.0.0")!=="0.0.0"&&(e.headers["content-type"]=e.body.getContentType(),e.body=e.body.toStream()):e.body!==null&&typeof URLSearchParams<"u"&&e.body instanceof URLSearchParams?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=e.body.map(t=>encodeURIComponent(t.key)+"="+encodeURIComponent(t.val)).join("&")):e.body!==null&&Object.isObject(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json; charset=utf-8",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded; charset=utf-8",e.body="")))}get(e){return this.request({...e,method:"GET"})}post(e){return this.request({...e,method:"POST"})}put(e){return this.request({...e,method:"PUT"})}del(e){return this.request({...e,method:"DELETE"})}upload(e){return new Error("unreachable")}download(e){return new Error("unreachable")}onTimeoutError=function(e,t,s=null){console.error("http timeout",s),t.status=-4,t.statusText="TIMEOUT",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-1,errmsg:(t.response.status??t.status)+", 网络请求超时!"}:t.body="网络请求超时!"};onNetworkError(e,t,s=null){console.error("http error",s),t.status=-1,t.statusText="NETWORK FAIL",e.responseType=="text"&&e.dataType=="json"?t.body={errno:-2,errmsg:(t.response.status??t.status)+", 网络请求错误!"}:t.body="网络请求错误!"}async request(e){const t=Object.assign(this.getDefaultRequest(),this.config,e);let s=this.getDefaultResponse();t.method=t.method.toUpperCase(),Object.defineProperties(t,{response:{value:s,enumerable:!1,configurable:!0,writable:!0}}),Object.defineProperties(s,{request:{value:t,enumerable:!1,configurable:!0,writable:!0},response:{value:null,enumerable:!1,configurable:!0,writable:!0},parent:{value:null,enumerable:!1,configurable:!0,writable:!0}}),this.fillUrl(t),this.fillHeaders(t),this.fillBody(t);let n=async(o,a)=>await this.send(o,a);for(let o=this.middlewares.length-1;o>=0;o--){const a=n,l=this.middlewares[o].bind(this);n=async(i,r)=>await l(i,r,a)}return await n(t,s),s}send(e,t){}install(e,t={}){e.config.globalProperties.$http=this;for(const s in t)this[s]=t[s]}globalMethods(){globalThis.httpGet=this.get.bind(this),globalThis.httpPost=this.post.bind(this),globalThis.httpPut=this.put.bind(this),globalThis.httpDelete=this.del.bind(this),globalThis.httpUpload=this.upload.bind(this),globalThis.httpDownload=this.download.bind(this)}}exports.HttpQuickBase=d;