httpquick 1.1.8 → 1.1.9

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.
@@ -0,0 +1 @@
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;
@@ -1,19 +1,12 @@
1
- var h = Object.defineProperty;
2
- var p = (o, e, t) => e in o ? h(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var a = (o, e, t) => p(o, typeof e != "symbol" ? e + "" : e, t);
4
- class b {
1
+ class u {
2
+ // 默认请求
3
+ config = {};
4
+ // 请求编号 debug使用的
5
+ requestId = 0;
6
+ // 请求中间件
7
+ middlewares = [];
5
8
  // 构造函数
6
9
  constructor(e = {}) {
7
- // 默认请求
8
- a(this, "config", {});
9
- // 请求编号 debug使用的
10
- a(this, "requestId", 0);
11
- // 请求中间件
12
- a(this, "middlewares", []);
13
- // 超时错误处理
14
- a(this, "onTimeoutError", function(e, t, s) {
15
- 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 = "网络请求超时!";
16
- });
17
10
  Object.assign(this.config, e);
18
11
  }
19
12
  // 更新配置
@@ -64,8 +57,7 @@ class b {
64
57
  }
65
58
  // 填充请求体
66
59
  fillBody(e) {
67
- var t;
68
- (e.method == "POST" || e.method == "PUT") && (e.filePath || (e.body !== null && typeof FormData < "u" && e.body instanceof FormData ? typeof process < "u" && (((t = process == null ? void 0 : process.versions) == null ? void 0 : t.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((s) => encodeURIComponent(s.key) + "=" + encodeURIComponent(s.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 = "")));
60
+ (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 = "")));
69
61
  }
70
62
  // get请求
71
63
  get(e) {
@@ -91,6 +83,10 @@ class b {
91
83
  download(e) {
92
84
  return new Error("unreachable");
93
85
  }
86
+ // 超时错误处理
87
+ onTimeoutError = function(e, t, s = null) {
88
+ 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 = "网络请求超时!";
89
+ };
94
90
  // 网络错误处理
95
91
  onNetworkError(e, t, s = null) {
96
92
  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 = "网络请求错误!";
@@ -106,12 +102,12 @@ class b {
106
102
  response: { value: null, enumerable: !1, configurable: !0, writable: !0 },
107
103
  parent: { value: null, enumerable: !1, configurable: !0, writable: !0 }
108
104
  }), this.fillUrl(t), this.fillHeaders(t), this.fillBody(t);
109
- let l = async (n, i) => await this.send(n, i);
110
- for (let n = this.middlewares.length - 1; n >= 0; n--) {
111
- const i = l, r = this.middlewares[n].bind(this);
112
- l = async (d, u) => await r(d, u, i);
105
+ let n = async (o, a) => await this.send(o, a);
106
+ for (let o = this.middlewares.length - 1; o >= 0; o--) {
107
+ const a = n, l = this.middlewares[o].bind(this);
108
+ n = async (i, r) => await l(i, r, a);
113
109
  }
114
- return await l(t, s), s;
110
+ return await n(t, s), s;
115
111
  }
116
112
  // 发送发送请求 abstract方法 需要子类实现
117
113
  send(e, t) {
@@ -126,5 +122,5 @@ class b {
126
122
  }
127
123
  }
128
124
  export {
129
- b as H
125
+ u as H
130
126
  };
package/dist/ajax.js CHANGED
@@ -1,27 +1,31 @@
1
- import { H as p } from "./HttpQuickBase-YasFsQ_r.js";
2
- class u extends p {
1
+ import { H as a } from "./HttpQuickBase-Bwjk70F3.js";
2
+ class l extends a {
3
3
  // 发送请求
4
4
  send(t, o) {
5
5
  let n = null, r = new Promise((s) => n = s);
6
6
  const e = o.response = new XMLHttpRequest();
7
7
  e.open(t.method, t.fullUrl, !0), e.timeout = t.timeout, e.withCredentials = t.withCredentials || !1, e.responseType = t.responseType;
8
- for (const [s, a] of Object.entries(t.headers))
9
- e.setRequestHeader(s, a);
8
+ for (const [s, p] of Object.entries(t.headers))
9
+ e.setRequestHeader(s, p);
10
10
  return e.ontimeout = (s) => {
11
11
  this.onTimeoutError(t, o, s), n();
12
12
  }, e.onerror = (s) => {
13
13
  this.onNetworkError(t, o, s), n();
14
14
  }, t.onprocess && e.upload.addEventListener("progress", t.onprocess), e.onreadystatechange = () => {
15
15
  if (!(e.readyState !== 4 || e.status == 0)) {
16
- if (e.status != 200)
17
- return this.onNetworkError(t, o, null), n();
18
16
  o.status = e.status, o.statusText = e.statusText, o.headers = Object.fromEntries(e.getAllResponseHeaders().trim().replaceAll("\r", "").split(`
19
- `).map((s) => [decodeURIComponent(s.substring(0, s.indexOf(": ")).toLowerCase()), decodeURIComponent(s.substring(s.indexOf(": ") + 2))])), t.responseType == "text" && t.dataType == "json" ? o.body = (JSON.parse0 || JSON.parse)(e.responseText) : t.responseType == "text" ? o.body = e.responseText : o.body = e.response, n();
17
+ `).map((s) => [decodeURIComponent(s.substring(0, s.indexOf(": ")).toLowerCase()), decodeURIComponent(s.substring(s.indexOf(": ") + 2))]));
18
+ try {
19
+ t.responseType == "text" && t.dataType == "json" ? o.body = JSON.parse(e.responseText) : t.responseType == "text" ? o.body = e.responseText : o.body = e.response;
20
+ } catch {
21
+ o.body = e.response;
22
+ }
23
+ n();
20
24
  }
21
25
  }, t.method == "POST" || t.method == "PUT" ? e.send(t.body) : e.send(), r;
22
26
  }
23
27
  }
24
28
  export {
25
- u as HttpQuick,
26
- p as HttpQuickBase
29
+ l as HttpQuick,
30
+ a as HttpQuickBase
27
31
  };
package/dist/fetch.js CHANGED
@@ -1,5 +1,5 @@
1
- import { H as u } from "./HttpQuickBase-YasFsQ_r.js";
2
- class h extends u {
1
+ import { H as l } from "./HttpQuickBase-Bwjk70F3.js";
2
+ class h extends l {
3
3
  // 发送请求
4
4
  async send(t, o) {
5
5
  try {
@@ -10,15 +10,17 @@ class h extends u {
10
10
  signal: s.signal,
11
11
  body: t.method == "POST" || t.method == "PUT" ? t.body : null
12
12
  }, e = o.response = await fetch(t.fullUrl, i);
13
- if (clearTimeout(n), e.status != 200)
14
- return this.onNetworkError(t, o, null);
15
- o.status = e.status, o.statusText = e.statusText;
16
- for (let [a, l] of e.headers.entries()) {
13
+ clearTimeout(n), o.status = e.status, o.statusText = e.statusText;
14
+ for (let [a, c] of e.headers.entries()) {
17
15
  a = a.toLowerCase();
18
- for (const r of l.split(", "))
19
- o.headers[a] = r;
16
+ for (const d of c.split(", "))
17
+ o.headers[a] = d;
18
+ }
19
+ try {
20
+ t.responseType == "text" && t.dataType == "json" ? o.body = await e.json() : t.responseType == "text" ? o.body = await e.text() : o.body = e.body;
21
+ } catch {
22
+ o.body = e.body;
20
23
  }
21
- t.responseType == "text" && t.dataType == "json" ? o.body = await e.json() : t.responseType == "text" ? o.body = await e.text() : o.body = e.body;
22
24
  } catch (s) {
23
25
  return s.code == 20 ? this.onTimeoutError(t, o, s) : this.onNetworkError(t, o, s);
24
26
  }
@@ -26,5 +28,5 @@ class h extends u {
26
28
  }
27
29
  export {
28
30
  h as HttpQuick,
29
- u as HttpQuickBase
31
+ l as HttpQuickBase
30
32
  };
package/dist/fibjs.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./HttpQuickBase-Djux5ry4.cjs"),n=require("http"),d=require("util");class i extends o.HttpQuickBase{send(e,s){try{const t=n.request(e.method,e.fullUrl,{headers:e.headers,body:e.body||""});if(t.status!==200)return this.onNetworkError(e,s,null);s.status=t.statusCode,s.statusText=t.statusMessage;for(let a of t.headers.keys()){const r=t.headers.all(a);a=a.toLowerCase();for(const u of r)s.headers[a]=u}e.responseType=="text"&&e.dataType=="json"?s.body=Buffer.isBuffer(t.data)?JSON.parse(t.data.toString("utf8")):typeof t.data=="string"?JSON.parse(t.data):t.data:e.responseType=="text"?s.body=t.data.toString("utf8"):s.body=t.data}catch(t){return this.onTimeoutError(e,s,t)}}request(e){return d.sync(async s=>await super.request(s))(e)}}exports.HttpQuickBase=o.HttpQuickBase;exports.HttpQuick=i;
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;
package/dist/fibjs.js CHANGED
@@ -1,34 +1,36 @@
1
- import { H as u } from "./HttpQuickBase-YasFsQ_r.js";
2
- import d from "http";
3
- import n from "util";
4
- class y extends u {
1
+ import { H as d } from "./HttpQuickBase-Bwjk70F3.js";
2
+ import u from "http";
3
+ import f from "util";
4
+ class c extends d {
5
5
  // 发送请求
6
- send(e, s) {
6
+ send(a, e) {
7
7
  try {
8
- const t = d.request(e.method, e.fullUrl, {
9
- headers: e.headers,
10
- body: e.body || ""
8
+ const t = u.request(a.method, a.fullUrl, {
9
+ headers: a.headers,
10
+ body: a.body || ""
11
11
  });
12
- if (t.status !== 200)
13
- return this.onNetworkError(e, s, null);
14
- s.status = t.statusCode, s.statusText = t.statusMessage;
15
- for (let a of t.headers.keys()) {
16
- const o = t.headers.all(a);
17
- a = a.toLowerCase();
12
+ e.status = t.statusCode, e.statusText = t.statusMessage;
13
+ for (let s of t.headers.keys()) {
14
+ const o = t.headers.all(s);
15
+ s = s.toLowerCase();
18
16
  for (const r of o)
19
- s.headers[a] = r;
17
+ e.headers[s] = r;
18
+ }
19
+ try {
20
+ a.responseType == "text" && a.dataType == "json" ? e.body = Buffer.isBuffer(t.data) ? JSON.parse(t.data.toString("utf8")) : typeof t.data == "string" ? JSON.parse(t.data) : t.data : a.responseType == "text" ? e.body = Buffer.isBuffer(t.data) ? t.data.toString("utf8") : (typeof t.data == "string", t.data) : e.body = t.data;
21
+ } catch {
22
+ e.body = t.data;
20
23
  }
21
- e.responseType == "text" && e.dataType == "json" ? s.body = Buffer.isBuffer(t.data) ? JSON.parse(t.data.toString("utf8")) : typeof t.data == "string" ? JSON.parse(t.data) : t.data : e.responseType == "text" ? s.body = t.data.toString("utf8") : s.body = t.data;
22
24
  } catch (t) {
23
- return this.onTimeoutError(e, s, t);
25
+ return this.onTimeoutError(a, e, t);
24
26
  }
25
27
  }
26
28
  // 同步请求
27
- request(e) {
28
- return n.sync(async (s) => await super.request(s))(e);
29
+ request(a) {
30
+ return f.sync(async (e) => await super.request(e))(a);
29
31
  }
30
32
  }
31
33
  export {
32
- y as HttpQuick,
33
- u as HttpQuickBase
34
+ c as HttpQuick,
35
+ d as HttpQuickBase
34
36
  };
@@ -1,2 +1,2 @@
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";var f=Object.defineProperty;var b=(a,i,l)=>i in a?f(a,i,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[i]=l;var d=(a,i,l)=>b(a,typeof i!="symbol"?i+"":i,l);class i{constructor(e={}){d(this,"config",{});d(this,"requestId",0);d(this,"middlewares",[]);d(this,"onTimeoutError",function(e,t,o){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="网络请求超时!"});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){var t;(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(((t=process==null?void 0:process.versions)==null?void 0:t.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(o=>encodeURIComponent(o.key)+"="+encodeURIComponent(o.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")}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 r=async(s,n)=>await this.send(s,n);for(let s=this.middlewares.length-1;s>=0;s--){const n=r,u=this.middlewares[s].bind(this);r=async(h,c)=>await u(h,c,n)}return await r(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 l extends i{send(e,t){let o=null,r=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,u]of Object.entries(e.headers))s.setRequestHeader(n,u);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)){if(s.status!=200)return this.onNetworkError(e,t,null),o();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))])),e.responseType=="text"&&e.dataType=="json"?t.body=(JSON.parse0||JSON.parse)(s.responseText):e.responseType=="text"?t.body=s.responseText:t.body=s.response,o()}},e.method=="POST"||e.method=="PUT"?s.send(e.body):s.send(),r}}a.HttpQuick=l,a.HttpQuickBase=i,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
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"})}));
package/dist/node.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./HttpQuickBase-Djux5ry4.cjs");class u extends i.HttpQuickBase{send(t,o){let n=null,r=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,a]of Object.entries(t.headers))e.setRequestHeader(s,a);return e.ontimeout=s=>{this.onTimeoutError(t,o,s),n()},e.onerror=s=>{this.onNetworkError(t,o,s),n()},e.onreadystatechange=()=>{if(!(e.readyState!==4||e.status==0)){if(e.status!=200)return this.onNetworkError(t,o,null),n();o.status=e.status,o.statusText=e.statusText,o.headers=Object.fromEntries(e.getAllResponseHeaders().trim().replaceAll("\r","").split(`
2
- `).map(s=>[decodeURIComponent(s.substring(0,s.indexOf(": ")).toLowerCase()),decodeURIComponent(s.substring(s.indexOf(": ")+2))])),t.responseType=="text"&&t.dataType=="json"?o.body=JSON.parse(e.responseText):t.responseType=="text"?o.body=e.responseText:o.body=e.response,n()}},t.method=="POST"||t.method=="PUT"?e.send(t.body):e.send(),r}}exports.HttpQuickBase=i.HttpQuickBase;exports.HttpQuick=u;
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(`
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,27 +1,31 @@
1
- import { H as i } from "./HttpQuickBase-YasFsQ_r.js";
2
- class u extends i {
1
+ import { H as a } from "./HttpQuickBase-Bwjk70F3.js";
2
+ class l extends a {
3
3
  // 发送请求
4
4
  send(t, o) {
5
5
  let n = null, r = new Promise((s) => n = s);
6
6
  const e = o.response = new XMLHttpRequest();
7
7
  e.open(t.method, t.fullUrl, !0), e.timeout = t.timeout, e.withCredentials = t.withCredentials || !1, e.responseType = t.responseType;
8
- for (const [s, a] of Object.entries(t.headers))
9
- e.setRequestHeader(s, a);
8
+ for (const [s, p] of Object.entries(t.headers))
9
+ e.setRequestHeader(s, p);
10
10
  return e.ontimeout = (s) => {
11
11
  this.onTimeoutError(t, o, s), n();
12
12
  }, e.onerror = (s) => {
13
13
  this.onNetworkError(t, o, s), n();
14
- }, e.onreadystatechange = () => {
14
+ }, t.onprocess && e.upload.addEventListener("progress", t.onprocess), e.onreadystatechange = () => {
15
15
  if (!(e.readyState !== 4 || e.status == 0)) {
16
- if (e.status != 200)
17
- return this.onNetworkError(t, o, null), n();
18
16
  o.status = e.status, o.statusText = e.statusText, o.headers = Object.fromEntries(e.getAllResponseHeaders().trim().replaceAll("\r", "").split(`
19
- `).map((s) => [decodeURIComponent(s.substring(0, s.indexOf(": ")).toLowerCase()), decodeURIComponent(s.substring(s.indexOf(": ") + 2))])), t.responseType == "text" && t.dataType == "json" ? o.body = JSON.parse(e.responseText) : t.responseType == "text" ? o.body = e.responseText : o.body = e.response, n();
17
+ `).map((s) => [decodeURIComponent(s.substring(0, s.indexOf(": ")).toLowerCase()), decodeURIComponent(s.substring(s.indexOf(": ") + 2))]));
18
+ try {
19
+ t.responseType == "text" && t.dataType == "json" ? o.body = JSON.parse(e.responseText) : t.responseType == "text" ? o.body = e.responseText : o.body = e.response;
20
+ } catch {
21
+ o.body = e.response;
22
+ }
23
+ n();
20
24
  }
21
25
  }, t.method == "POST" || t.method == "PUT" ? e.send(t.body) : e.send(), r;
22
26
  }
23
27
  }
24
28
  export {
25
- u as HttpQuick,
26
- i as HttpQuickBase
29
+ l as HttpQuick,
30
+ a as HttpQuickBase
27
31
  };
package/dist/uniapp.js CHANGED
@@ -1,12 +1,5 @@
1
- var p = Object.defineProperty;
2
- var l = (d, o, e) => o in d ? p(d, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[o] = e;
3
- var i = (d, o, e) => l(d, typeof o != "symbol" ? o + "" : o, e);
4
- import { H as f } from "./HttpQuickBase-YasFsQ_r.js";
5
- class y extends f {
6
- constructor() {
7
- super(...arguments);
8
- i(this, "methods", {});
9
- }
1
+ import { H as i } from "./HttpQuickBase-Bwjk70F3.js";
2
+ class u extends i {
10
3
  // 上传文件
11
4
  upload(e) {
12
5
  return this.request({ ...e, method: "POST", func: "uploadFile" });
@@ -17,9 +10,8 @@ class y extends f {
17
10
  }
18
11
  // 发送请求
19
12
  async send(e, a) {
20
- var n;
21
- let r = null, u = new Promise((s) => r = s);
22
- this.methods[e.func || "request"]({
13
+ let s = null, n = new Promise((o) => s = o);
14
+ const d = {
23
15
  method: e.method,
24
16
  url: e.fullUrl,
25
17
  header: e.headers,
@@ -33,23 +25,26 @@ class y extends f {
33
25
  responseType: e.responseType,
34
26
  dataType: e.dataType,
35
27
  timeout: e.timeout,
36
- success: (s) => r({ ...s, err: !1 }),
37
- fail: (s) => r({ ...s, err: !0 })
38
- });
39
- const t = a.response = await u;
28
+ success: (o) => s({ ...o, err: !1 }),
29
+ fail: (o) => s({ ...o, err: !0 })
30
+ };
31
+ e.func == "uploadFile" ? uni.uploadFile(d) : e.func == "downloadFile" ? uni.downloadFile(d) : uni.request(d);
32
+ const t = a.response = await n;
40
33
  if (a.err = t.err, t.err && t.errMsg == "request:fail timeout")
41
- return this.onTimeoutError(e, a);
34
+ return this.onTimeoutError(e, a, t.err);
42
35
  if (t.err)
43
- return this.onNetworkError(e, a);
44
- if (t.statusCode != 200)
45
- return this.onNetworkError(e, a);
36
+ return this.onNetworkError(e, a, t.err);
46
37
  a.status = t.statusCode, a.statusText = "OK";
47
- for (const s in t.header)
48
- a.headers[s.toLowerCase()] = t.header[s];
49
- e.responseType == "text" && e.dataType == "json" && typeof t.data == "string" ? a.body = (JSON.parse0 || JSON.parse)(t.data) : e.responseType == "text" && e.dataType == "json" && typeof t.data == "object" ? a.body = ((n = t.data) == null ? void 0 : n.object2model()) ?? t.data : (e.responseType == "text", a.body = t.data);
38
+ for (const o in t.header)
39
+ a.headers[o.toLowerCase()] = t.header[o];
40
+ try {
41
+ e.responseType == "text" && e.dataType == "json" && typeof t.data == "string" ? a.body = JSON.parse(t.data) : (e.responseType == "text" && e.dataType == "json" || e.responseType == "text", a.body = t.data);
42
+ } catch {
43
+ a.body = t.data;
44
+ }
50
45
  }
51
46
  }
52
47
  export {
53
- y as HttpQuick,
54
- f as HttpQuickBase
48
+ u as HttpQuick,
49
+ i as HttpQuickBase
55
50
  };
package/dist/xcx.js CHANGED
@@ -1,67 +1,50 @@
1
- var l = Object.defineProperty;
2
- var d = (r, s, t) => s in r ? l(r, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[s] = t;
3
- var i = (r, s, t) => d(r, typeof s != "symbol" ? s + "" : s, t);
4
- import { H as f } from "./HttpQuickBase-YasFsQ_r.js";
5
- class c extends f {
6
- // 构造函数
7
- constructor(t = {}) {
8
- super(t);
9
- // 平台
10
- i(this, "platform", null);
11
- if (typeof uni < "u")
12
- this.setPlatform(uni), this.setPlatform(uni.$h5);
13
- else if (typeof wx < "u")
14
- this.setPlatform(wx);
15
- else
16
- throw new Error("unknown platform");
17
- }
18
- // 设置平台
19
- setPlatform(t = null) {
20
- return this.platform = t, this;
21
- }
1
+ import { H as r } from "./HttpQuickBase-Bwjk70F3.js";
2
+ class u extends r {
22
3
  // 上传文件
23
- upload(t) {
24
- return this.request({ ...t, method: "POST", func: "uploadFile" });
4
+ upload(e) {
5
+ return this.request({ ...e, method: "POST", func: "uploadFile" });
25
6
  }
26
7
  // 下载文件
27
- download(t) {
28
- return this.request({ ...t, method: "POST", func: "downloadFile" });
8
+ download(e) {
9
+ return this.request({ ...e, method: "POST", func: "downloadFile" });
29
10
  }
30
11
  // 发送请求
31
- async send(t, e) {
32
- const [u, n, p] = Promise.channel();
33
- this.platform[t.func || "req"]({
34
- method: t.method,
35
- url: t.fullUrl,
36
- header: t.headers,
37
- data: t.body,
38
- formData: t.formData,
12
+ async send(e, a) {
13
+ let s = null, n = new Promise((o) => s = o);
14
+ const d = {
15
+ method: e.method,
16
+ url: e.fullUrl,
17
+ header: e.headers,
18
+ data: e.body,
19
+ formData: e.formData,
39
20
  // upload fromData
40
- name: t.name || "file",
21
+ name: e.name || "file",
41
22
  // upload file param name
42
- filePath: t.filePath,
23
+ filePath: e.filePath,
43
24
  // upload file path
44
- responseType: t.responseType,
45
- dataType: "",
46
- // req.dataType,
47
- timeout: t.timeout,
48
- success: (a) => n({ ...a, err: !1 }),
49
- fail: (a) => n({ ...a, err: !0 })
50
- });
51
- const o = e.response = await u;
52
- if (e.err = o.err, o.err && o.errMsg == "request:fail timeout")
53
- return this.onTimeoutError(t, e);
54
- if (o.err)
55
- return this.onNetworkError(t, e);
56
- if (o.statusCode != 200)
57
- return this.onNetworkError(t, e, null);
58
- e.status = o.statusCode, e.statusText = "OK";
59
- for (const a in o.header)
60
- e.headers[a.toLowerCase()] = o.header[a];
61
- t.responseType == "text" && t.dataType == "json" ? e.body = JSON.parse(o.data) : (t.responseType == "text", e.body = o.data);
25
+ responseType: e.responseType,
26
+ dataType: e.dataType,
27
+ timeout: e.timeout,
28
+ success: (o) => s({ ...o, err: !1 }),
29
+ fail: (o) => s({ ...o, err: !0 })
30
+ };
31
+ e.func == "uploadFile" ? wx.uploadFile(d) : e.func == "downloadFile" ? wx.downloadFile(d) : wx.request(d);
32
+ const t = a.response = await n;
33
+ if (a.err = t.err, t.err && t.errMsg == "request:fail timeout")
34
+ return this.onTimeoutError(e, a, t.err);
35
+ if (t.err)
36
+ return this.onNetworkError(e, a, t.err);
37
+ a.status = t.statusCode, a.statusText = "OK";
38
+ for (const o in t.header)
39
+ a.headers[o.toLowerCase()] = t.header[o];
40
+ try {
41
+ e.responseType == "text" && e.dataType == "json" && typeof t.data == "string" ? a.body = JSON.parse(t.data) : (e.responseType == "text" && e.dataType == "json" || e.responseType == "text", a.body = t.data);
42
+ } catch {
43
+ a.body = t.data;
44
+ }
62
45
  }
63
46
  }
64
47
  export {
65
- c as HttpQuick,
66
- f as HttpQuickBase
48
+ u as HttpQuick,
49
+ r as HttpQuickBase
67
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpquick",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
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",
@@ -51,10 +51,10 @@
51
51
  "preview": "vite preview"
52
52
  },
53
53
  "devDependencies": {
54
- "@vitejs/plugin-vue": "^5.2.4",
55
- "pinia": "^3.0.2",
56
- "vite": "^6.3.5",
57
- "vue": "^3.5.15",
54
+ "@vitejs/plugin-vue": "^6.0.1",
55
+ "pinia": "^3.0.3",
56
+ "vite": "^7.1.5",
57
+ "vue": "^3.5.21",
58
58
  "vue-router": "^4.5.1"
59
59
  }
60
60
  }
@@ -1 +0,0 @@
1
- "use strict";var h=Object.defineProperty;var p=(o,e,t)=>e in o?h(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var a=(o,e,t)=>p(o,typeof e!="symbol"?e+"":e,t);class c{constructor(e={}){a(this,"config",{});a(this,"requestId",0);a(this,"middlewares",[]);a(this,"onTimeoutError",function(e,t,s){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="网络请求超时!"});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){var t;(e.method=="POST"||e.method=="PUT")&&(e.filePath||(e.body!==null&&typeof FormData<"u"&&e.body instanceof FormData?typeof process<"u"&&(((t=process==null?void 0:process.versions)==null?void 0:t.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(s=>encodeURIComponent(s.key)+"="+encodeURIComponent(s.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")}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 l=async(n,i)=>await this.send(n,i);for(let n=this.middlewares.length-1;n>=0;n--){const i=l,r=this.middlewares[n].bind(this);l=async(d,u)=>await r(d,u,i)}return await l(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=c;