httpquick 1.1.0 → 1.1.2
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/fibjs.cjs +1 -1
- package/dist/fibjs.js +1 -1
- package/dist/httpquick.umd.cjs +2 -0
- package/package.json +6 -6
- package/dist/api/postJson.json +0 -12
package/dist/fibjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./HttpQuickBase-D0-rw_KI.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./HttpQuickBase-D0-rw_KI.cjs"),n=require("http"),d=require("util");class i extends u.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 o=t.headers.all(a);a=a.toLowerCase();for(const r of o)s.headers[a]=r}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.HttpQuickFibjs=i;
|
package/dist/fibjs.js
CHANGED
|
@@ -13,7 +13,7 @@ class y extends u {
|
|
|
13
13
|
return this.onNetworkError(e, s, null);
|
|
14
14
|
s.status = t.statusCode, s.statusText = t.statusMessage;
|
|
15
15
|
for (let a of t.headers.keys()) {
|
|
16
|
-
|
|
16
|
+
const o = t.headers.all(a);
|
|
17
17
|
a = a.toLowerCase();
|
|
18
18
|
for (const r of o)
|
|
19
19
|
s.headers[a] = r;
|
|
@@ -0,0 +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 c=Object.defineProperty;var b=(a,i,l)=>i in a?c(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.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){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.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,f)=>await u(h,f,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()},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.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.HttpQuickAjax=l,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "httpquick",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"main": "dist/
|
|
21
|
+
"main": "dist/httpquick.umd.cjs",
|
|
22
22
|
"import": "dist/ajax.js",
|
|
23
23
|
"require": "dist/node.cjs",
|
|
24
24
|
"exports": {
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"dev": "vite",
|
|
51
|
-
"build":
|
|
51
|
+
"build":"vite build && vite build --mode=umd --emptyOutDir=false",
|
|
52
52
|
"preview": "vite preview"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@vitejs/plugin-vue": "^5.2.
|
|
56
|
-
"pinia": "^3.0.
|
|
57
|
-
"vite": "^6.2.
|
|
55
|
+
"@vitejs/plugin-vue": "^5.2.3",
|
|
56
|
+
"pinia": "^3.0.2",
|
|
57
|
+
"vite": "^6.2.6",
|
|
58
58
|
"vue": "^3.5.13",
|
|
59
59
|
"vue-router": "^4.5.0"
|
|
60
60
|
}
|
package/dist/api/postJson.json
DELETED