MCPcopy
hub / github.com/gaotianliuyun/gao / http

Function http

lib/live2cms.js:213–247  ·  view source on GitHub ↗
(url, options = {})

Source from the content-addressed store, hash-verified

211}
212
213const http = function (url, options = {}) {
214 if(options.method ==='POST' && options.data){
215 options.body = JSON.stringify(options.data);
216 options.headers = Object.assign({'content-type':'application/json'}, options.headers);
217 }
218 options.timeout = request_timeout;
219 if(!options.headers){
220 options.headers = {};
221 }
222 let keys = Object.keys(options.headers).map(it=>it.toLowerCase());
223 if(!keys.includes('referer')){
224 options.headers['Referer'] = getHome(url);
225 }
226 if(!keys.includes('user-agent')){
227 options.headers['User-Agent'] = UA;
228 }
229 console.log(JSON.stringify(options.headers));
230 try {
231 const res = req(url, options);
232 // if(options.headers['Authorization']){
233 // console.log(res.content);
234 // }
235 res.json = () => res&&res.content ? JSON.parse(res.content) : null;
236 res.text = () => res&&res.content ? res.content:'';
237 return res
238 }catch (e) {
239 return {
240 json() {
241 return null
242 }, text() {
243 return ''
244 }
245 }
246 }
247};
248["get", "post"].forEach(method => {
249 http[method] = function (url, options = {}) {
250 return http(url, Object.assign(options, {method: method.toUpperCase()}));

Callers 15

_0x14ad14Function · 0.70
_0x2bd6dbFunction · 0.70
_0x2b250aFunction · 0.70
_0x32ae57Function · 0.70
_0x591b50Function · 0.70
_0x4dba23Function · 0.70
live2cms.jsFile · 0.70
_0x20eff0Function · 0.70
_0x96fcbFunction · 0.70
_0x5e25b8Function · 0.70
_0x10d0c2Function · 0.70

Calls 1

getHomeFunction · 0.70

Tested by

no test coverage detected