httpquick 1.1.13 → 1.1.14
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/{HttpQuickBase-JDE128ZY.js → HttpQuickBase-C2llxW7e.js} +2 -2
- package/dist/HttpQuickBase-jKUSsx5s.cjs +1 -0
- package/dist/ajax.js +1 -1
- package/dist/fetch.js +1 -1
- package/dist/fibjs.cjs +1 -1
- package/dist/fibjs.js +1 -1
- package/dist/httpquick.umd.cjs +2 -2
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/uniapp.js +1 -1
- package/dist/xcx.js +1 -1
- package/package.json +1 -1
- package/dist/HttpQuickBase-CYqLvzuS.cjs +0 -1
|
@@ -50,11 +50,11 @@ class u {
|
|
|
50
50
|
}
|
|
51
51
|
// 填充请求头
|
|
52
52
|
fillHeaders(e) {
|
|
53
|
-
e.responseType == "text" && e.dataType == "json" ? e.headers.Accept = "application/json
|
|
53
|
+
e.responseType == "text" && e.dataType == "json" ? e.headers.Accept = "application/json" : e.responseType == "text" && e.dataType == "xml" ? e.headers.Accept = "application/xml" : e.responseType == "text" ? e.headers.Accept = "text/plain" : (e.responseType == "arraybuffer" || e.responseType == "blob") && (e.headers.Accept = "application/octet-stream");
|
|
54
54
|
}
|
|
55
55
|
// 填充请求体
|
|
56
56
|
fillBody(e) {
|
|
57
|
-
(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
|
|
57
|
+
(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", e.body = e.body.toString()) : e.body !== null && Array.isArray(e.body) ? (e.headers["content-type"] = "application/x-www-form-urlencoded", 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", e.body = this.obj2query(e.body)) : e.json !== null ? (e.headers["content-type"] = "application/json", e.body = JSON.stringify(e.json)) : (e.headers["content-type"] = "application/x-www-form-urlencoded", e.body = "")));
|
|
58
58
|
}
|
|
59
59
|
// get请求
|
|
60
60
|
get(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:{},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":e.responseType=="text"&&e.dataType=="xml"?e.headers.Accept="application/xml":e.responseType=="text"?e.headers.Accept="text/plain":(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",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded",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",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded",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}});let n=async(o,a)=>{this.fillUrl(o),this.fillHeaders(o),this.fillBody(o),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
package/dist/fetch.js
CHANGED
package/dist/fibjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./HttpQuickBase-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./HttpQuickBase-jKUSsx5s.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
package/dist/httpquick.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(a
|
|
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}}
|
|
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={};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:{},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":e.responseType=="text"&&e.dataType=="xml"?e.headers.Accept="application/xml":e.responseType=="text"?e.headers.Accept="text/plain":(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",e.body=e.body.toString()):e.body!==null&&Array.isArray(e.body)?(e.headers["content-type"]="application/x-www-form-urlencoded",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",e.body=this.obj2query(e.body)):e.json!==null?(e.headers["content-type"]="application/json",e.body=JSON.stringify(e.json)):(e.headers["content-type"]="application/x-www-form-urlencoded",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}});let l=async(s,n)=>{this.fillUrl(s),this.fillHeaders(s),this.fillBody(s),await this.send(s,n)};for(let s=this.middlewares.length-1;s>=0;s--){const n=l,d=this.middlewares[s].bind(this);l=async(p,h)=>await d(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 r 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,d]of Object.entries(e.headers))s.setRequestHeader(n,d);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=r,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 r=require("./HttpQuickBase-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./HttpQuickBase-jKUSsx5s.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
package/dist/uniapp.js
CHANGED
package/dist/xcx.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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:{},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}});let n=async(o,a)=>{this.fillUrl(o),this.fillHeaders(o),this.fillBody(o),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;
|