MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / httpRequest

Method httpRequest

jlld.js:399–458  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

397 }
398 }
399 async httpRequest(options) {
400 let t = {
401 ...options
402 };
403 if (!t.headers) {
404 t.headers = {}
405 }
406 if (t.params) {
407 t.url += '?' + this.queryStr(t.params);
408 }
409 t.method = t.method.toLowerCase();
410 if (t.method === 'get') {
411 delete t.headers['Content-Type'];
412 delete t.headers['Content-Length'];
413 delete t["body"]
414 }
415 if (t.method === 'post') {
416 let contentType;
417
418 if (!t.body) {
419 t.body = ""
420 } else {
421 if (typeof t.body == "string") {
422 if (this.isJSONString(t.body)) {
423 contentType = 'application/json'
424 } else {
425 contentType = 'application/x-www-form-urlencoded'
426 }
427 } else if (this.isJson(t.body)) {
428 t.body = JSON.stringify(t.body);
429 contentType = 'application/json';
430 }
431 }
432 if (!t.headers['Content-Type']) {
433 t.headers['Content-Type'] = contentType;
434 }
435 delete t.headers['Content-Length'];
436 }
437 if (this.isNode()) {
438 this.initGotEnv(t);
439 let httpResult = await this.got(t);
440 if (this.isJSONString(httpResult.body)) {
441 httpResult.body = JSON.parse(httpResult.body)
442 }
443 return httpResult;
444 }
445 if (this.isQuanX()) {
446 t.method = t.method.toUpperCase()
447 return new Promise((resolve, reject) => {
448 $task.fetch(t).then(response => {
449 if (this.isJSONString(response.body)) {
450 response.body = JSON.parse(response.body)
451 }
452 resolve(response)
453 }, reason => {
454 reject(reason.err)
455 })
456 })

Callers 4

task_listMethod · 0.45
task_likeMethod · 0.45
task_shareMethod · 0.45
art_listMethod · 0.45

Calls 6

queryStrMethod · 0.45
isJSONStringMethod · 0.45
isJsonMethod · 0.45
isNodeMethod · 0.45
initGotEnvMethod · 0.45
isQuanXMethod · 0.45

Tested by

no test coverage detected