MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / httpRequest

Method httpRequest

ruilanCar.js:350–408  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

348 }
349 }
350 async httpRequest(options) {
351 let t = {
352 ...options
353 };
354 if (!t.headers) {
355 t.headers = {}
356 }
357 if (t.params) {
358 t.url += '?' + this.queryStr(t.params);
359 }
360 t.method = t.method.toLowerCase();
361 if (t.method === 'get') {
362 delete t.headers['Content-Type'];
363 delete t.headers['Content-Length'];
364 delete t.headers['content-type'];
365 delete t.headers['content-length'];
366 delete t["body"]
367 }
368 if (t.method === 'post') {
369 let ContentType;
370 if (!t.body) {
371 t.body = ""
372 } else {
373 if (typeof t.body == "string") {
374 if (this.isJSONString(t.body)) {
375 ContentType = 'application/json'
376 } else {
377 ContentType = 'application/x-www-form-urlencoded'
378 }
379 } else if (this.isJson(t.body)) {
380 t.body = JSON.stringify(t.body);
381 ContentType = 'application/json';
382 }
383 }
384 if (!t.headers['Content-Type'] || !t.headers['content-type']) {
385 t.headers['Content-Type'] = ContentType;
386 }
387 delete t.headers['Content-Length'];
388 }
389 if (this.isNode()) {
390 this.initGotEnv(t);
391 let httpResult = await this.got(t);
392 if (this.isJSONString(httpResult.body)) {
393 httpResult.body = JSON.parse(httpResult.body)
394 }
395 return httpResult;
396 }
397 if (this.isQuanX()) {
398 t.method = t.method.toUpperCase()
399 return new Promise((resolve, reject) => {
400 $task.fetch(t).then(response => {
401 if (this.isJSONString(response.body)) {
402 response.body = JSON.parse(response.body)
403 }
404 resolve(response)
405 })
406 })
407 }

Callers 1

taskRequestMethod · 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