Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exportPdf: function(noteId, callback) {
var me = this;
// console.log(me.getUrl('note/exportPdf', {noteId: noteId}));
needle.get(me.getUrl('note/exportPdf', {noteId: noteId}), function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);
}
// log(resp.body);
/*
{ 'accept-ranges': 'bytes',
'content-disposition': 'inline; filename="logo.png"',
'content-length': '8583',
'content-type': 'image/png',
date: 'Mon, 19 Jan 2015 15:01:47 GMT',
*/
var body = resp.body;
if(typeof body == "object" && body.Msg === false) {
return callback(false, "", body.Msg);
el = $(el);
var row = {
Title: el.find('.result-link a').text(),
URL: 'http://stackoverflow.com'+el.find('.result-link a').attr('href')
};
results.push(row);
}.bind(this));
return results;
}
needle.get('http://stackoverflow.com/search?q='+querystring.escape(q), defaultHeaders, function(error, response, body) {
var results = parseString(body);
var sendTo = from; // send privately
if (isChannel(to)) {
sendTo = to; // send publicly
}
client.say(sendTo,
'Here are the top 3 Stackoverflow results for the search "'+q+'": '
+'\n1: '+results[0].URL
+'\n2: '+results[1].URL
+'\n3: '+results[2].URL
+'\nMore results at: http://stackoverflow.com/search?q='+querystring.escape(q)
);
});
releases.get_stable_version = function(cb) {
needle.get(releases_url + latest_text, function(err, resp, body) {
var ver = body && body.toString().trim();
// log('Latest upstream version: ' + ver);
cb(err, ver);
});
}
var assert = require('assert')
var needle = require('needle')
var url = 'http://localhost:3001/t0/a0/b0?a1=b1&a2=b2'
console.log('GET '+url)
needle.get(url,function(err,res){
assert.ok( !err )
assert.equal( res.headers.h0, 'i0' )
assert.deepEqual(res.body,{ r0: 'r0b0', r1: 'r1b1', r2: 'r2b2', x0: 'ry0' })
})
url = 'http://localhost:3001/t0/a0/b0?a1=b1',
console.log('POST '+url)
needle.post(
url,
{a2:'b2',c:'c'},
{json:true},
function(err,res){
assert.ok( !err )
assert.deepEqual(res.body,
{ r0: 'r0pb0', r1: 'pr1b1', r2: 'r2b2', x0: 'ry0', c: 'C' })
}
var proxyUrl = opts.proxy ||
process.env.http_proxy ||
process.env.HTTP_PROXY ||
process.env.npm_config_proxy;
if (proxyUrl) {
if (/^https?:\/\//i.test(proxyUrl)) {
log.verbose('download', 'using proxy url: "%s"', proxyUrl);
requestOpts.proxy = proxyUrl;
} else {
log.warn('download', 'ignoring invalid "proxy" config setting: "%s"', proxyUrl);
}
}
try {
req = require('needle').get(requestOpts.uri, requestOpts);
} catch (e) {
return callback(e);
}
if (req) {
req.on('response', function (res) {
log.http(res.statusCode, uri);
});
}
return callback(null,req);
}
new Promise((resolve, reject) => {
const tmp = path.join(stagingArea, file)
const out = fs.createWriteStream(tmp)
debug('fetchElectron', tmp, url)
needle
.get(url)
.pipe(out)
.on('error', (err: Error) => {
console.error(err)
reject(err)
})
.on('finish', () => resolve(tmp))
})
}
var proxyUrl = opts.proxy ||
process.env.http_proxy ||
process.env.HTTP_PROXY ||
process.env.npm_config_proxy;
if (proxyUrl) {
if (/^https?:\/\//i.test(proxyUrl)) {
log.verbose('download', 'using proxy url: "%s"', proxyUrl);
requestOpts.proxy = proxyUrl;
} else {
log.warn('download', 'ignoring invalid "proxy" config setting: "%s"', proxyUrl);
}
}
try {
req = require('needle').get(requestOpts.uri, requestOpts);
} catch (e) {
return callback(e);
}
if (req) {
req.on('response', function (res) {
log.http(res.statusCode, uri);
});
}
return callback(null,req);
}
that.get = function(success, failure) {
var parsedUrl = Url.parse(url, false);
needle.get(requestUrl(parsedUrl), basicAuthFrom(parsedUrl), function(error, response, body) {
if (!error && response.statusCode == 200) {
success(body);
} else {
failure();
}
});
};
return that;
return new Promise>((resolve, reject) => {
Needle.get(url, { follow: 3 }, (error, response) => {
if (error != undefined) {
reject(error);
return;
}
const result: HttpResponse = {
statusCode: response.statusCode as number,
statusMessage: response.statusMessage as string,
body: response.raw
};
resolve(result);
});
});
}
connector.getAccessToken(function (error, token) {
var tok = token;
headers['Authorization'] = 'Bearer ' + token;
headers['Content-Type'] = 'application/octet-stream';
return needle.get(attachment.contentUrl, { headers: headers });
});
}