Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
peer = library.logic.peers.create(peer);
var req = {
url: 'http://' + peer.ip + ':' + peer.port + url,
method: options.method,
headers: __private.headers,
timeout: library.config.peers.options.timeout
};
if (options.data) {
req.body = options.data;
}
popsicle.request(req)
.use(popsicle.plugins.parse(['json'], false))
.then(function (res) {
if (res.status !== 200) {
// Remove peer
__private.removePeer({peer: peer, code: 'ERESPONSE ' + res.status}, req.method + ' ' + req.url);
return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
} else {
var headers = peer.applyHeaders(res.headers);
var report = library.schema.validate(headers, schema.headers);
if (!report) {
// Remove peer
__private.removePeer({peer: peer, code: 'EHEADERS'}, req.method + ' ' + req.url);
return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
import * as view from "./page";
const popsicle = require("popsicle");
const shuffle = require("shuffle-array");
const baseUrl = "http://localhost:5000";
const dictionary = {} as { [word: string]: number };
let dictionarySize;
popsicle.request(createGetUrl("/words/list")).then(res => {
res.body.split("\n").forEach((word, index) => dictionary[word] = index);
dictionarySize = Object.keys(dictionary).length;
console.log(`words loaded (count of ${ dictionarySize })`);
});
const main = document.getElementById("main");
view.render(main, {
report: message => {
return popsicle.request({
url: createGetUrl("/spam/report"),
method: "POST",
body: {
message
}
});
},
t.test('support no proxy', function (t) {
return popsicle_1.request(server.url())
.use(proxy({ proxy: proxyServer.url(), noProxy: url_1.parse(server.url()).hostname }))
.then(function (res) {
t.equal(res.status, 200);
t.equal(res.body, 'server /');
});
});
t.test('after', function (t) {
t.test('use proxy option', function (t) {
var proxy = createProxy({
proxy: proxyServer.url()
});
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, 'proxy ' + server.url());
});
});
t.test('support no proxy', function (t) {
private send() {
popsicle.request({
url: createGetUrl("/messages"),
method: "POST",
body: {
message: this.textarea.value
}
}).then(res => console.log("message sent"));
}
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,
function analyze(indexes: number[], reals: number[]): Promise<{ spam: boolean; confidence: number; }> {
return popsicle
.request(createGetUrl("/words/vector", "ids", indexes))
.use(popsicle.plugins.parse("json"))
.then(response => {
let result: Vector = null;
reals.forEach(index => {
let vector = new Vector(response.body.words[index].vector);
if (result === null) {
result = vector;
} else {
result.add(vector);
}
});
return popsicle
(retry) =>
popsicle
.request(req)
.use(parsingPlugin)
.catch(retry),
{
module.exports = toSymbol => {
if (typeof toSymbol === 'string') {
toSymbol = toSymbol.toUpperCase();
} else {
toSymbol = 'USD';
}
return popsicle.request({
method: 'POST',
url: 'https://min-api.cryptocompare.com/data/price',
query: {
fsym: 'ETH',
tsyms: toSymbol
}
})
.use(popsicle.plugins.parse(['json']))
.then(resp => resp.body)
.then(data => {
const symbols = Object.keys(data);
return symbols
.map(symbol => `${symbol}: ${data[symbol]}`);
});
};
private poll() {
popsicle
.request(`${ baseUrl }/messages`)
.use(popsicle.plugins.parse("json"))
.then(res => {
if (res.body.message) {
const id = generateMessageId();
this.setState({
messages: [{ id, content: res.body.message }].concat(this.state.messages)
});
setTimeout(() => {
this.props.check(res.body.message).then(res => {
this.updateMessageState(id, res.spam);
});
}, 2500);
}