@1 ./html-css-js/raw/master/js/lib/http/syncHTTPGet.js @2 ./_js/raw/master/_http_______/http-sync-only.js @3 ./_js/raw/master/_http_______/http-lite.js @4 ./html-css-js/raw/master/js/lib/http/http.js @5 ./html-css-js/raw/master/js/lib/http.js @6 ./_js/raw/master/_http_______/http.js @7 ./_js/raw/http-lite/http.js @8 ./_js/raw/http/http.js @@ 3// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 4// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 5// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 6// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 7// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 8// `props` are the same as in https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 6 8 6// check if var D exists. expected when: `Function('D','var D=D||1; return D')(2) --> 2` 8// check if var D exists. expected when: `Function('D','var D=D||1; return D')(2) --> 2` 6 8 6var D = D || globalThis.D || function(){ 8var D = D || globalThis.D || function(){ 6 return { 8 return { 6 _ok: [], 8 _ok: [], 6 _fail: [], 8 _fail: [], 6 _stat: 0, 8 _stat: 0, 6 resolve(...args){ return this._ok .map(a => a(...args)); }, 8 resolve(...args){ return this._ok .map(a => a(...args)); }, 6 reject (...args){ return this._fail.map(a => a(...args)); }, 8 reject (...args){ return this._fail.map(a => a(...args)); }, 6 then (fn) { this._ok .push(fn); return this; }, 8 then (fn) { this._ok .push(fn); return this; }, 6 catch(fn) { this._fail.push(fn); return this; }, 8 catch(fn) { this._fail.push(fn); return this; }, 6 }; 8 }; 6} 8} 2 4 6 8 1function syncHTTPGet(url) { 2function HTTP(method, url, data, props) { 'use strict'; 3function HTTP(method, url, data, a1, a2) { 'use strict'; 4function HTTP(method, url, data, a1, a2) { 'use strict'; 5function HTTP(method, url, data, a1, a2) { 'use strict'; 6function HTTP(method, url, data, a1, a2) { 'use strict'; 7function HTTP(method, url, data, a1, a2) { 'use strict'; 8function HTTP(method, url, data, a1, a2) { 'use strict'; 3 // usage: HTTP(method, url, data, async, props) // where async = boolean 5 // usage: HTTP(method, url, data, async, props) // where async = boolean 6 // usage: HTTP(method, url, data, async, props) // where async = boolean 7 // usage: HTTP(method, url, data, async, props) // where async = boolean 8 // usage: HTTP(method, url, data, async, props) // where async = boolean 3 // usage: HTTP(method, url, data, callback, props) // where callback = function 5 // usage: HTTP(method, url, data, callback, props) // where callback = function 6 // usage: HTTP(method, url, data, callback, props) // where callback = function 7 // usage: HTTP(method, url, data, callback, props) // where callback = function 8 // usage: HTTP(method, url, data, callback, props) // where callback = function 3 // usage: HTTP(method, url, data, props) // where props = object // note: async is false -> sync 5 // usage: HTTP(method, url, data, props) // where props = object // note: async is false -> sync 6 // usage: HTTP(method, url, data, props) // where props = object // note: async is false -> sync 7 // usage: HTTP(method, url, data, props) // where props = object // note: async is false -> sync 8 // usage: HTTP(method, url, data, props) // where props = object // note: async is false -> sync 3 // usage: HTTP(method, url) // then data reponse will be retuned // note: async is false -> sync 6 // usage: HTTP(method, url) // then data reponse will be retuned // note: async is false -> sync 7 // usage: HTTP(method, url) // then data reponse will be retuned // note: async is false -> sync 8 // usage: HTTP(method, url) // then data reponse will be retuned // note: async is false -> sync 5 3 7 6 8 2 var /*async=false,*/ callback, props; 4 var async, callback, props; 5 var async, callback, props; 6 var async, callback, props; 3 var async, callback, props; 7 var async, callback, props; 8 var async, callback, props; 2 4 5 if (typeof a1 === 'object') { 3 if (typeof a1 === 'object') { 4 if (typeof a1 === 'object') { 6 if (typeof a1 === 'object') { 7 if (typeof a1 === 'object') { 8 if (typeof a1 === 'object') { 3 async = false; 4 async = false; 5 async = false; 6 async = false; 7 async = false; 8 async = false; 3 props = a1; 4 props = a1; 5 props = a1; 6 props = a1; 7 props = a1; 8 props = a1; 5 // a2 is ignored 3 // a2 is ignored 6 // a2 is ignored 7 // a2 is ignored 8 // a2 is ignored 3 } else if (typeof a1 === 'function') { 4 } else if (typeof a1 === 'function') { 5 } else if (typeof a1 === 'function') { 6 } else if (typeof a1 === 'function') { 7 } else if (typeof a1 === 'function') { 8 } else if (typeof a1 === 'function') { 4 async = true; callback = a1; 3 async = true; callback = a1; 5 async = true; callback = a1; 6 async = true; callback = a1; 7 async = true; callback = a1; 8 async = true; callback = a1; 3 props = a2; 4 props = a2; 5 props = a2; 6 props = a2; 7 props = a2; 8 props = a2; 3 } else { 4 } else { 5 } else { 6 } else { 7 } else { 8 } else { 3 async = a1; 4 async = a1; 5 async = a1; 6 async = a1; 7 async = a1; 8 async = a1; 3 props = a2; 4 props = a2; 5 props = a2; 6 props = a2; 7 props = a2; 8 props = a2; 3 } 4 } 5 } 6 } 7 } 8 } 3 5 6 7 8 5 3 4 6 7 8 1 let xhr = new XMLHttpRequest(); 2 var xhr = new XMLHttpRequest(); 3 var xhr = new XMLHttpRequest(); 4 var xhr = new XMLHttpRequest(); 5 var xhr = new XMLHttpRequest(); 6 var xhr = new XMLHttpRequest(); 7 var xhr = new XMLHttpRequest(); 8 var xhr = new XMLHttpRequest(); 1 xhr.open( 'GET', url, false ); // false => sync request 2 xhr.open( method||"GET", url||".", false/*async*/ ); 3 xhr.open( method||"GET", url||".", async ); 4 xhr.open( method, url||".", async ) 5 xhr.open( method||"GET", url||".", async ); 6 xhr.open( method||"GET", url||".", async ); 7 xhr.open( method||"GET", url||".", async ); 8 xhr.open( method||"GET", url||".", async ); 2 3 5 6 4 7 8 2 for (var k in props) { 3 for (var k in props) { 4 for (var k in props) { 5 for (var k in props) { 6 for (var k in props) { 7 for (var k in props) { 8 for (var k in props) { 2 if (typeof xhr[k] === "function") { 5 if (typeof xhr[k] === "function") { 6 if (typeof xhr[k] === "function") { 4 if (typeof xhr[k] === "function") { 7 if (typeof xhr[k] === "function") { 3 if (typeof xhr[k] === "function") { 8 if (typeof xhr[k] === "function") { 4 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 3 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 2 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 5 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 6 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 7 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 8 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 4 } else { 2 } else { 3 } else { 7 } else { 8 } else { 5 } else { 6 } else { 2 xhr[k] = props[k]; 4 xhr[k] = props[k]; 3 xhr[k] = props[k]; 7 xhr[k] = props[k]; 8 xhr[k] = props[k]; 5 xhr[k] = props[k]; 6 xhr[k] = props[k]; 2 } 3 } 4 } 6 } 7 } 8 } 5 } 2 } 3 } 4 } 7 } 8 } 5 } 6 } 5 6 5 6 2 2 3 7 8 2 3 3 7 8 4 5 var d; 6 var d; 8 var d; 4 if (async) { 4 if (window.D) { // https://github.com/denisde4ev/html-css-js/blob/master/js/lib/deferred/deferred.js 4 var d = xhr.d = D({callOnce:true}); 4 xhr.then = d.then.bind(d); 4 } 4 } 5 if (async && window.D) { 6 if (async && typeof D !== 'undefined') { 8 if (async && typeof D !== 'undefined') { 5 d = xhr.d = D({callOnce:true}); 6 d = xhr.d = D({callOnce:true}); 8 d = xhr.d = D({callOnce:true}); 6 //xhr.then = d.then.bind(d); 8 //xhr.then = d.then.bind(d); 5 }; 6 }; 8 }; 5 6 8 4 if (callback || d) { 2 if (callback) { 3 if (callback) { 5 if (callback || d) { 6 if (callback || d) { 8 if (callback || d) { 2 xhr.addEventListener("loadend", function (evt) { 3 xhr.addEventListener("loadend", function (evt) { 4 xhr.addEventListener('readystatechange', function (e) { 5 xhr.onreadystatechange = function (evt) { 6 xhr.addEventListener("loadend", function (evt) { debugger 8 xhr.addEventListener("loadend", function (evt) { debugger 2 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 3 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 5 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 6 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 8 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 4 if (e.target.readyState !== 4) return; 5 if (evt.target.readyState !== 4) return; 2 // if (evt.target.readyState !== 4) return; 4 var xhr = e.target; 4 var status = xhr.status; 4 var txt = e.target.responseText; 4 4 if ( status === 0 || ( 200 <= status&&status < 400 ) ) { 4 4 4 4 if (callback) callback(null, txt, e, xhr); 3 // if (evt.target.readyState !== 4) return; 6 // if (evt.target.readyState !== 4) return; 8 // if (evt.target.readyState !== 4) return; 3 5 6 8 2 // var args = [evt.target.responseText, evt.target.status, evt, this]; 3 var args = [evt.target.responseText, evt.target.status, evt, this]; 5 var args = [evt.target.responseText, evt.target.status, evt, this]; 6 var args = [evt.target.responseText, evt.target.status, evt, this]; 8 var args = [evt.target.responseText, evt.target.status, evt, this]; 5 if (callback) { 6 if (callback) { 8 if (callback) { 2 // callback.apply(this, args); 2 callback.call(this, evt.target.responseText, evt.target.status, evt, void 0, this); 3 callback.apply(this, args); 5 callback.apply(this, args); 6 callback.apply(this, args); 8 callback.apply(this, args); 5 } 6 } 8 } 5 if (d) { 6 if (d) { 8 if (d) { 4 if (d) { 5 if (evt.target.status === 200) { 6 //if (evt.target.status === 200) { 8 //if (evt.target.status === 200) { 6 if (evt.target.status[0] === 2) { 4 if (evt.target.status.toString()[0] == 2) { 8 if (evt.target.status.toString()[0] == 2) { 4 d.resolve(txt, e, xhr); 5 d.resolve.apply(d, args); 6 d.resolve.apply(d, args); 8 d.resolve.apply(d, args); 5 } else { 6 } else { 8 } else { 4 } else { 4 if (callback) callback(status, txt, e, xhr); 5 d.reject. apply(d, args); 4 d.reject(txt, e, xhr); 6 d.reject. apply(d, args); 8 d.reject. apply(d, args); 8 if (!d._fail.length) { // throw manually error when no one suscribed for error. 8 throw new Error({ 8 message: 'HTTP status: '+evt.target.status, toString(){return this.message}, 8 xhr, 8 evt 8 }); 8 } 4 } 5 } 6 } 8 } 5 } 6 } 8 } 5 } 4 }); 2 }); 3 }); 6 }); 8 }); 4 } 2 } 3 } 5 } 6 } 8 } 2 3 5 5 3 2 6 6 1 xhr.send({}); 2 xhr.send(data); 3 xhr.send(data); 4 xhr.send(data); 5 xhr.send(data); 6 xhr.send(data); 7 xhr.send(data); 8 xhr.send(data); 2 3 4 6 8 8 8 6 7 if (callback) { 7 xhr.addEventListener("loadend", function (evt) { 7 // (never used) // if (props.onreadystatechange) props.onreadystatechange.call(this,evt); // since was overwritten by this fn, call it here 7 // if (evt.target.readyState !== 4) return; 7 7 var args = [evt.target.responseText, evt.target.status, evt,void 0,this]; 7 callback.apply(this, args); 7 }) 7 } 3 if (async) return xhr; 4 if (async) { 2 //if (async) 6 if (async) { 8 if (async) { 7 if (async) { 4 return xhr; 6 return xhr; 2// return xhr; 7 return xhr; 8 return xhr; 2//} 6 } 7 } 8 } 8 7 7 2 7 7 3 2 if (xhr.status !== 200) { 3 if (xhr.status !== 200) { 6 if (xhr.status !== 200) { 7 if (xhr.status !== 200) { 8 if (xhr.status !== 200) { 2 xhr.stack = new Error().stack; // good practice? 3 xhr.stack = new Error().stack; // good practice? 6 xhr.stack = new Error().stack; // good practice? 7 xhr.stack = new Error().stack; // good practice? 2 throw xhr; 3 throw xhr; 6 throw xhr; 7 throw xhr; 8 throw new Error({ 8 message: 'HTTP status: '+xhr.status, toString(){return this.message}, 8 xhr 8 }); 3 } 4 } 6 } 7 } 2 } 8 } 2 return xhr.responseText; 3 return xhr.responseText; 6 return xhr.responseText; 7 return xhr.responseText; 8 return xhr.responseText; 5 4 4 var status = xhr.status; 1 var s = xhr.status; 1 xhr._ok = s === 0 || 200 <= s && s < 400; 4 if (!( status === 0 || ( 200 <= status&&status < 400 ) )) throw xhr; 5 return async ? xhr : xhr.responseText; 5 //if (!async) return xhr.responseText; 4 if (a1==null&&!a2) return xhr.responseText; 5 //return xhr; 4 return xhr; 1 return xhr; 1} 2} 3} 4} 5} 6} 7} 8} 1 2 3 4 5 6 7 8 1minify: function syncHTTPGet(u,x,s){x=new XMLHttpRequest;x.open("GET",u,!1),x.send({});s=x.status;x._ok=0===s||200<=s&&s<400;return x} 1minify: function syncHTTPGetText(u,x,s){x=new XMLHttpRequest;x.open("GET",u,!1),x.send({});if(s=x.status,0===s||200<=s&&s<300)return x.response} 1var hGet = syncHTTPGet; 2var hGet = function (url, props ) { return HTTP('GET', url, null, props ); }; 3var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 4var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 5var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 6var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 7var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 8var hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 2var hPost = function (url, data, props ) { return HTTP('POST', url, data, props ); }; 3var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 4var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 5var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 6var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 7var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 8var hPost = function (url, data, a1, a2) { return HTTP('POST', url, data, a1, a2); }; 4 4// console.time('hGet') 4// and then one liner: hGet('/data1') -> sting from request 4// console.timeEnd('hGet') 5 5 5 5// import D from /js/lib/deferred/deferred.js; 5HTTP.get('/assets/js/deferred.js', true).d.then(function (t) { 5 console.info(t) 5}) 7 8 6 7 8 6 7 8 6 7 8 6 7 8 6 7 8 6 7if (typeof _debug_httplib !== 'undefined') { 8if (typeof _debug_httplib !== 'undefined') { 6if (typeof _debug_httplib !== 'undefined') { 7 // import D from /assets/js/deferred.js; 8 // import D from /assets/js/deferred.js; 6 // import D from /assets/js/deferred.js; 7 if (typeof D === 'undefined') { 8 if (typeof D === 'undefined') { 6 if (typeof D === 'undefined') { 7 D = Function('D', hGet('/assets/js/deferred.js') + '\nreturn D;')(); 8 D = Function('D', hGet('/assets/js/deferred.js') + '\nreturn D;')(); 6 D = Function('D', hGet('/assets/js/deferred.js') + '\nreturn D;')(); 7 } 8 } 6 } 7 8 6 7 if (typeof D !== 'undefined') { 8 if (typeof D !== 'undefined') { 6 if (typeof D !== 'undefined') { 7 hGet('/assets/js/deferred.js', true).d.then(function (t) { 8 hGet('/assets/js/deferred.js', true).d.then(function (t) { 6 hGet('/assets/js/deferred.js', true).d.then(function (t) { 7 console.info(t) 8 console.info(t) 6 console.info(t) 7 }); 8 }); 6 }); 7 8 6 7 } 8 } 6 } 7} 8} 6} @ @ 4 4// var `props` is simular to https://github.com/anonyco/SuperSimpleExtensibleSmallXMLHttpRequestWrapper#documentation 4 4function HTTP(method, url, body, a1, a2) { 4 var async = a1; 4 var props = a2; 4 var callback; 4 4 if (typeof a1 === 'function') { 4 async = true; 4 callback = a1; 4 } else if (typeof a1 === 'object') { 4 props = a1; 4 async = false; 4 } 4 4 var xhr = new XMLHttpRequest; 4 xhr.open(method, url||".", async) 4 4 for (var k in props) 4 if (typeof xhr[k] === "function") 4 props[k].forEach(xhr[k].apply.bind(xhr[k],xhr)); 4 else 4 xhr[k] = props[k] 4 4 xhr.send(body||{}); 4 4 if (async) { 4 if (window.D) { // https://github.com/denisde4ev/html-css-js/blob/master/js/deferred/deferred.js 4 var d = xhr.d = D({callOnce:true}); 4 xhr.then = d.then.bind(d); 4 } 4 if (callback || d) { 4 xhr.addEventListener('readystatechange', function (e) { 4 if (e.target.readyState !== 4) return; 4 var xhr = e.target; 4 var status = xhr.status; 4 var txt = e.target.responseText; 4 4 if ( status === 0 || ( 200 <= status&&status < 400 ) ) { 4 if (callback) callback(null, txt, e, xhr); 4 if (d) d.resolve(txt, e, xhr); 4 } else { 4 if (callback) callback(status, txt, e, xhr); 4 if (d) d.reject(txt, e, xhr); 4 } 4 }); 4 } 4 return xhr; 4 } 4 4 var status = xhr.status; 4 if (!( status === 0 || ( 200 <= status&&status < 400 ) )) throw xhr; 4 if (a1==null&&!a2) return xhr.responseText; 4 return xhr; 4} 4 4hGet = function (url, a1, a2) { return HTTP('GET', url, null, a1, a2); }; 4hPost = function (url, body, a1, a2) { return HTTP('POST', url, body, a1, a2); }; 4 4// console.time('hGet') 4// and then one liner: hGet('/data1') -> sting from request 4// console.timeEnd('hGet') 4 @@<==> __12888__.find-http.js.cksum @@ @@cksum: can't open './_js/raw/master/http/http-lite.js': Invalid argument @@./_js/raw/master/http/http-lite.js -> /^/ github.com/denisde4ete/http.js @@ @@cksum: can't open './_js/raw/master/http/http.js': Invalid argument @@./_js/raw/master/http/http.js -> /^/ https://github.com/denisde4ev/_js/raw/http/http.js @@ @@ @@---- @@ @@1750947102 491 ./html-css-js/raw/master/js/lib/http/syncHTTPGet.js @@1490923416 1205 ./_js/raw/master/_http_______/http-sync-only.js @@2732247235 1691 ./_js/raw/master/_http_______/http-lite.js @@2810281898 1695 ./html-css-js/raw/master/js/lib/http/http.js @@2556570075 1854 ./html-css-js/raw/master/js/lib/http.js @@2680961180 2872 ./_js/raw/master/_http_______/http.js @@1616834065 2017 ./_js/raw/http-lite/http.js @@74260332 3116 ./_js/raw/http/http.js @@ @@ @@---- @@ @@ @@i=0 @@for f in \ @@ ./html-css-js/raw/master/js/lib/http/syncHTTPGet.js \ @@ ./_js/raw/master/_http_______/http-sync-only.js \ @@ ./_js/raw/master/_http_______/http-lite.js \ @@ ./html-css-js/raw/master/js/lib/http/http.js \ @@ ./html-css-js/raw/master/js/lib/http.js \ @@ ./_js/raw/master/_http_______/http.js \ @@ ./_js/raw/http-lite/http.js \ @@ ./_js/raw/http/http.js \ @@; @@do @@ i=$((i+1)) @@ sed "s/^/$i/" -- "$f" @@ echo @@ echo @@ # printf %s\\n "@@ $i $f" @@done