Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
resolve.push(req)
}
}
if (options.fallbackOnFavicon !== false) {
if (result.html && result.html.icons == null) {
const faviconUrl = resolveUrl(contentUrl, '/favicon.ico')
const req = get({
url: faviconUrl,
headers: {
'User-Agent': options.userAgent
},
transport: createTransport({ type: 'stream' })
})
.use(status(200))
const res = req.then(
(res) => {
// Initialize the favicon.
result.html.icons = [{
url: faviconUrl,
type: parse(res.get('content-type')).type
}]
// Abort immediately response.
res.body.on('error', (): void => undefined)
req.abort()
},
() => {/* Noop request/response errors. */}
function fetch () {
console.log('Fetching "' + fixtureUrl + '"...')
return popsicle.request({
url: fixtureUrl,
transport: popsicle.createTransport({
type: 'buffer',
jar: popsicle.jar(),
maxBufferSize: 20 * 1000 * 1000
})
})
.then(function (res) {
return mkdir(dir)
.then(function () {
console.log('Writing "' + filename + '"...')
const meta = {
originalUrl: fixtureUrl,
url: res.url,
headers: res.headers,
status: res.status,
statusText: res.statusText
t.test('support no proxy', function (t) {
var proxy = createProxy({
proxy: proxyServer.url(),
noProxy: url_1.parse(server.url()).hostname
});
return popsicle_1.request({
url: server.url(),
transport: popsicle_1.createTransport({
agent: proxy(server.url())
})
})
.then(function (res) {
t.equal(res.status, 200);
t.equal(res.body, 'server /');
});
});
t.test('after', function (t) {
library.logger.info(dapp.transactionId, `Downloading: ${dapp.link}`);
function cleanup(err) {
library.logger.error(dapp.transactionId, `Download failed: ${err.message}`);
fs.exists(tmpPath, (exists) => {
if (exists) {
fs.unlink(tmpPath);
}
return setImmediate(serialCb, err.message);
});
}
const request = popsicle.get({
url: dapp.link,
transport: popsicle.createTransport({ type: 'stream' })
});
request.then((res) => {
if (res.status !== 200) {
return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
}
const stream = fs.createWriteStream(tmpPath);
stream.on('error', cleanup);
stream.on('finish', () => {
library.logger.info(dapp.transactionId, 'Finished downloading');
stream.close(serialCb);
});
performDownload: function (serialCb) {
library.logger.info(dapp.transactionId, 'Downloading: ' + dapp.link);
function cleanup (err) {
library.logger.error(dapp.transactionId, 'Download failed: ' + err.message);
fs.exists(tmpPath, function (exists) {
if (exists) { fs.unlink(tmpPath); }
return setImmediate(serialCb, err.message);
});
}
var request = popsicle.get({
url: dapp.link,
transport: popsicle.createTransport({type: 'stream'})
});
request.then(function (res) {
if (res.status !== 200) {
return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
}
var stream = fs.createWriteStream(tmpPath);
stream.on('error', cleanup);
stream.on('finish', function () {
library.logger.info(dapp.transactionId, 'Finished downloading');
stream.close(serialCb);
});
exports.readHttp = throat(5, function readHttp(url) {
var rejectUnauthorized = rc_1.default.rejectUnauthorized, ca = rc_1.default.ca, key = rc_1.default.key, cert = rc_1.default.cert, userAgent = rc_1.default.userAgent;
return popsicle.get({
url: url,
headers: {
'User-Agent': template(userAgent, {
nodeVersion: process.version,
platform: process.platform,
arch: process.arch,
typingsVersion: pkg.version
})
},
transport: popsicle.createTransport({
ca: ca,
key: key,
cert: cert,
agent: exports.proxy(url),
rejectUnauthorized: rejectUnauthorized
})
})
.use(popsicleStatus(200))
.use(function (request, next) {
if (request.Url.host === registryURL.host) {
if (store_1.default.get('clientId')) {
request.set('Typings-Client-Id', store_1.default.get('clientId'));
}
return next().then(function (response) {
if (response.get('Typings-Client-Id')) {
store_1.default.set('clientId', response.get('Typings-Client-Id'));
peer: BasePeerType,
options: PeerRequestOptions
): Promise<{ body: T; peer: PeerType }> {
const url = options.url;
const thePeer = this.peersLogic.create(peer);
const req = {
body: options.data,
headers: {
...(this.systemModule.headers as any),
accept: 'application/octet-stream',
'content-type': 'application/octet-stream',
...options.headers,
},
method: options.method,
timeout: this.appConfig.peers.options.timeout,
transport: popsicle.createTransport({ type: 'buffer' }),
url: `http://${peer.ip}:${peer.port}${url}`,
};
const parsingPlugin = (
request: popsicle.Request,
next: () => Promise
) => {
return next().then((response) => response);
};
let res: popsicle.Response;
try {
res = await promiseRetry(
(retry) =>
popsicle
.request(req)
exports.readHttp = throat(5, function readHttp(url) {
var rejectUnauthorized = rc_1.default.rejectUnauthorized, ca = rc_1.default.ca, key = rc_1.default.key, cert = rc_1.default.cert, userAgent = rc_1.default.userAgent;
return popsicle.get({
url: url,
headers: {
'User-Agent': template(userAgent, {
nodeVersion: process.version,
platform: process.platform,
arch: process.arch,
typingsVersion: pkg.version
})
},
transport: popsicle.createTransport({
ca: ca,
key: key,
cert: cert,
agent: exports.proxy(url),
rejectUnauthorized: rejectUnauthorized
})
})
.use(popsicleStatus(200))
.use(function (request, next) {
if (request.Url.host === registryURL.host) {
if (store_1.default.get('clientId')) {
request.set('Typings-Client-Id', store_1.default.get('clientId'));
}
return next().then(function (response) {
if (response.get('Typings-Client-Id')) {
store_1.default.set('clientId', response.get('Typings-Client-Id'));
performDownload: function (serialCb) {
library.logger.info(dapp.transactionId, 'Downloading: ' + dapp.link);
function cleanup (err) {
library.logger.error(dapp.transactionId, 'Download failed: ' + err.message);
fs.exists(tmpPath, function (exists) {
if (exists) { fs.unlink(tmpPath); }
return setImmediate(serialCb, err.message);
});
}
var request = popsicle.get({
url: dapp.link,
transport: popsicle.createTransport({type: 'stream'})
});
request.then(function (res) {
if (res.status !== 200) {
return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
}
var stream = fs.createWriteStream(tmpPath);
stream.on('error', cleanup);
stream.on('finish', function () {
library.logger.info(dapp.transactionId, 'Finished downloading');
stream.close(serialCb);
});