(opts, callback = () => {})
| 783 | } |
| 784 | |
| 785 | get(opts, callback = () => {}) { |
| 786 | if (opts.headers) { |
| 787 | delete opts.headers['Content-Type'] |
| 788 | delete opts.headers['Content-Length'] |
| 789 | } |
| 790 | if (this.isSurge() || this.isLoon()) { |
| 791 | if (this.isSurge() && this.isNeedRewrite) { |
| 792 | opts.headers = opts.headers || {} |
| 793 | Object.assign(opts.headers, { |
| 794 | 'X-Surge-Skip-Scripting': false |
| 795 | }) |
| 796 | } |
| 797 | $httpClient.get(opts, (err, resp, body) => { |
| 798 | if (!err && resp) { |
| 799 | resp.body = body |
| 800 | resp.statusCode = resp.status |
| 801 | } |
| 802 | callback(err, resp, body) |
| 803 | }) |
| 804 | } else if (this.isQuanX()) { |
| 805 | if (this.isNeedRewrite) { |
| 806 | opts.opts = opts.opts || {} |
| 807 | Object.assign(opts.opts, { |
| 808 | hints: false |
| 809 | }) |
| 810 | } |
| 811 | $task.fetch(opts).then( |
| 812 | (resp) => { |
| 813 | const { |
| 814 | statusCode: status, |
| 815 | statusCode, |
| 816 | headers, |
| 817 | body |
| 818 | } = resp |
| 819 | callback(null, { |
| 820 | status, |
| 821 | statusCode, |
| 822 | headers, |
| 823 | body |
| 824 | }, body) |
| 825 | }, |
| 826 | (err) => callback(err) |
| 827 | ) |
| 828 | } else if (this.isNode()) { |
| 829 | this.initGotEnv(opts) |
| 830 | this.got(opts) |
| 831 | .on('redirect', (resp, nextOpts) => { |
| 832 | try { |
| 833 | if (resp.headers['set-cookie']) { |
| 834 | const ck = resp.headers['set-cookie'].map(this.cktough.Cookie.parse).toString() |
| 835 | if (ck) { |
| 836 | this.ckjar.setCookieSync(ck, null) |
| 837 | } |
| 838 | nextOpts.cookieJar = this.ckjar |
| 839 | } |
| 840 | } catch (e) { |
| 841 | this.logErr(e) |
| 842 | } |
no test coverage detected