(options)
| 332 | } |
| 333 | } |
| 334 | async httpRequest(options) { |
| 335 | const t = { |
| 336 | ...options |
| 337 | }; |
| 338 | if (!t.headers) { |
| 339 | t.headers = {} |
| 340 | } |
| 341 | if (t.params) { |
| 342 | t.url += '?' + this.queryStr(t.params); |
| 343 | } |
| 344 | t.method = t.method.toLowerCase() |
| 345 | if (t.method.toLowerCase() === 'get') { |
| 346 | delete t.headers['Content-Type']; |
| 347 | delete t.headers['Content-Length']; |
| 348 | delete t["body"] |
| 349 | } |
| 350 | if (t.method.toLowerCase() === 'post') { |
| 351 | let contentType |
| 352 | |
| 353 | if (!t.body) { |
| 354 | t.body = "" |
| 355 | } else { |
| 356 | if (typeof t.body == "string") { |
| 357 | if (this.isJSONString(t.body)) { |
| 358 | contentType = 'application/json' |
| 359 | } else { |
| 360 | contentType = 'application/x-www-form-urlencoded' |
| 361 | } |
| 362 | } else if (this.isJson(t.body)) { |
| 363 | t.body = JSON.stringify(t.body) |
| 364 | contentType = 'application/json' |
| 365 | } |
| 366 | } |
| 367 | if (!t.headers['Content-Type']) { |
| 368 | t.headers['Content-Type'] = contentType; |
| 369 | } |
| 370 | delete t.headers['Content-Length']; |
| 371 | } |
| 372 | if (this.isNode()) { |
| 373 | this.initGotEnv(t); |
| 374 | let httpResult = await this.got(t) |
| 375 | if (this.isJSONString(httpResult.body)) { |
| 376 | httpResult.body = JSON.parse(httpResult.body) |
| 377 | } |
| 378 | return httpResult; |
| 379 | } |
| 380 | } |
| 381 | randomNumber(length) { |
| 382 | const characters = '0123456789'; |
| 383 | return Array.from({ length }, () => characters[Math.floor(Math.random() * characters.length)]).join(''); |
no test coverage detected