MCPcopy Index your code
hub / github.com/totaljs/framework / download_response

Function download_response

utils.js:1468–1534  ·  view source on GitHub ↗
(res)

Source from the content-addressed store, hash-verified

1466}
1467
1468function download_response(res) {
1469
1470 var options = this.$options;
1471 var uri = this.$uri;
1472
1473 res._bufferlength = 0;
1474
1475 // We have redirect
1476 if (res.statusCode === 301 || res.statusCode === 302) {
1477
1478 if (options.redirect > 3) {
1479 options.canceled = true;
1480 options.timeoutid && clearTimeout(options.timeoutid);
1481 options.callback && options.callback(new Error('Too many redirects.'), null, null, null, null, options.param);
1482 res.req.removeAllListeners();
1483 res.req = null;
1484 res.removeAllListeners();
1485 res = null;
1486 return;
1487 }
1488
1489 options.redirect++;
1490
1491 var loc = res.headers['location'];
1492 var proto = loc.substring(0, 6);
1493
1494 if (proto !== 'http:/' && proto !== 'https:')
1495 loc = uri.protocol + '//' + uri.hostname + loc;
1496
1497 var tmp = Url.parse(loc);
1498 tmp.headers = uri.headers;
1499 // tmp.agent = false;
1500 tmp.method = uri.method;
1501 res.req.removeAllListeners();
1502 res.req = null;
1503
1504 if (options.proxy && tmp.protocol === 'https:') {
1505 // TLS?
1506 options.uri = tmp;
1507 download_call(options, request_call);
1508 return;
1509 }
1510
1511 if (!options.resolve) {
1512 res.removeAllListeners();
1513 res = null;
1514 return download_call(tmp, options);
1515 }
1516
1517 exports.resolve(loc, function(err, u) {
1518 if (!err)
1519 tmp.host = u.host;
1520 res.removeAllListeners();
1521 res = null;
1522 download_call(tmp, options);
1523 });
1524
1525 return;

Callers

nothing calls this directly

Calls 1

download_callFunction · 0.85

Tested by

no test coverage detected