function fetchVenues (center, callback) { var search = { ll: center.lat + ',' + center.lng, radius: '4000', categoryId: theaterCategoryId, intent: 'browse' } hq('/fours/venues/search?' + qs.stringify(search)) .pipe(concat(function (data) { callback(JSON.parse(data).response.venues); })); }
return function(diggerReq, diggerRes){ var req = hyperquest(baseurl + diggerReq.url, { method:diggerReq.method.toUpperCase(), headers:diggerReq.headers }) diggerReq .pipe(ndjson.stringify()) .pipe(req) .pipe(ndjson.parse()) .pipe(diggerRes) }
fetchVineSrc(vineurl, function(src){ console.log("vine movie src: " + src); id = src.match(/(videos\/.*\.mp4)/ig)[0].replace('videos/',''); id = id.slice(0,-4); filename = __dirname + "/media/" + id +".mp4"; var r = hyperquest(src); r.pipe(fs.createWriteStream(filename)) r.on("end", function(){ currentVineURL = 'media/'+id+'.mp4'; console.log("saved movie: " + currentVineURL); callback(currentVineURL); }); });
container.on('stream', function(stream){ if(!job.feedbackTarget){ logger.error('[no feedback target]') return } var req = hyperquest(job.feedbackTarget, { method:'POST' }) stream.pipe(req).pipe(process.stdout) stream.pipe(process.stdout) })
return new Promise((resolve, reject) => { request(options.url) .pipe(unzip.Parse()) .on('error', err => reject(err)) .on('entry', entry => { if (extname(entry.path) !== options.extname) { return entry.autodrain(); } //this.close(); resolve(entry); }); });
Machete.prototype.get = function() { var req = hyperquest(this.url); req.on('error', this._errored.bind(this)); req.on('response', function(res) { if (res.statusCode != 200) { this._errored('STATUS CODE -- ' + res.statusCode); return; } this._process(res); }.bind(this)); return this; }
app.get('/:x/:y', function (req, res) { res.header('Access-Control-Allow-Origin', '*') res.header('Access-Control-Allow-Methods', 'GET') var url = urlTemplate .replace('{x}', req.params.x) .replace('{y}', req.params.y) .replace('{key}', key) hyperquest(url) .pipe(JSONStream.parse('vectorQuery.layers.772.features.*')) .pipe(geojsonStream.stringify()) .pipe(res) })
function startStream(){ bs.reset(); console.log('start stream'); var r = hyperquest(url); r.pipe(bs); r.on('close', function(){ console.log('stream closed'); process.exit(); }); r.on('error', function(err){ console.log(err.message); }); }
var getDetails = function(url, callback) { var parsed = parse(url); var url = "http://www.mixcloud.com/player/details/?key=" + qs.escape(parsed.pathname); var bodyHandler = bl(function(err, data) { try { callback(null, JSON.parse(data.toString())); } catch (error) { callback(error, null); } }); hyperquest(url).pipe(bodyHandler); };
function overrustle(opts) { function parse(row) { return { timestamp: moment.utc(row.substring(1, 20)).toISOString(), user: row.substring(26, row.indexOf(': ')), message: row.substring(row.indexOf(': ') + 2) }; } const url = 'http://cors.maxogden.com/' + overrustleLogsUrl(opts); return hyperquest(url, { headers: {'X-Requested-With': 'dgg-chat-replay'} }).pipe(split2(parse)); }
MimeNode.prototype._getStream = function(content) { var contentStream; if (typeof content.pipe === 'function') { return content; } else if (content && typeof content.path === 'string' && !content.href) { return fs.createReadStream(content.path); } else if (content && typeof content.href === 'string') { return hyperquest(content.href); } else { contentStream = new PassThrough(); contentStream.end(content || ''); return contentStream; } };
files.forEach(function (file) { if (!/test-buffer.*/.test(file.name)) return var path if (file.name !== 'test-buffer-iterator.js') { path = __dirname + '/../test/node/' + file.name } else { path = __dirname + '/../test/es6/' + file.name } hyperquest(file.download_url, httpOpts) .pipe(split()) .pipe(testfixer(file.name)) .pipe(fs.createWriteStream(path)) })
function list (category, area, pickupDay) { var stream = resumer(write); pickupDay || (pickupDay = closestPickupDay()); request(url(area, category, pickupDay)).pipe(parser).pipe(stream); return stream; function write (data) { this.queue({ pickupDay: pickupDay, products: refine(data, vendors(data.vendors)) }); } }
port(function (port) { var erred = false; hyperquest('http://localhost:' + port + (optimised ? '/opt' : '') + path, function (err, res) { erred = err || res.statusCode >= 400; if (err) return cb(err); if (res.statusCode >= 400) { return cb(new Error('Server responded with status code ' + res.statusCode)); } }) .pipe(concat(function (err, res) { if (erred) return; if (err) return cb(err); return cb(null, res.toString()); })); })
function getURL(url, cb) { var stream = request(url); stream.on('response', function response(response) { if (response.statusCode === 302 || response.statusCode === 301) { getURL(response.headers.location, cb); } else if (response.statusCode !== 200) { cb(new Error('Server responeded with status code ' + response.statusCode + ' for ' + url)); } else { cb(null, stream); } }); stream.on('error', function (e) { cb(e); }); }
function search(options) { var tracks = []; hyperquest(options.uri) .pipe(JSONStream.parse(options.parsingKeys)) .pipe(through(function toTrack(track) { if (tracks.length < maxResults) { track = options.parseTrack(track); if (track) tracks.push(track); } }, end) ); function end() { options.callback(tracks); } }
port(function (port) { hyperquest('http://localhost:' + port + (optimised ? '/opt' : '') + path, {headers: {'Accept-Encoding':'gzip'}}, function (err, res) { if (err) return cb(err); if (res.statusCode >= 400) { var err = new Error('Server responded with status code ' + res.statusCode); err.statusCode = res.statusCode; return cb(err); } this.pipe(require('zlib').createGunzip()) .pipe(concat(function (res) { return cb(null, res.toString()); })); }) })
cert.urls.forEach(function(url) { requests++ request(url) .on('data', function(d) { if (!keys[url]) { return keys[url] = d.toString() } keys[url] += d.toString() }) .on('error', function(err) { delete keys[url] console.log(err) console.log('Failed to read a key from %s', url) }) .on('end', end) })
var ws = through.obj(function (query, enc, done) { var isPost = (opt.method || '').toLowerCase() === 'post' var url = isPost ? requestUrl : requestUrl + '?' + query var req = hyperquest(url, opt) req.on('error', onError).pipe(rs) if (isPost) { req.setHeader('content-type', 'application/x-www-form-urlencoded') req.setHeader('content-length', Buffer.byteLength(query)) } isPost && req.end(query) done() })
function request(uri, opts, cb) { if (typeof uri === 'object') { cb = opts; opts = uri; uri = undefined; } if (typeof opts === 'function') { cb = opts; opts = undefined; } if (!opts) opts = {}; if (uri !== undefined) opts.uri = uri; opts.headers = opts.headers || {}; opts.headers['Accept-Encoding'] = opts.headers['Accept-Encoding'] ? opts.headers['Accept-Encoding'] + ',gzip,deflate' : 'gzip,deflate'; var method = (opts.method || 'GET').toUpperCase(); var duplex = (method != 'GET' && method != 'DELETE'); var rs = through(); var ws = hyperquest(opts, function (err, res) { if (err) dup.emit('error', err); switch (res.headers['content-encoding']) { case 'gzip': res.headers['content-encoding'] = null; this.pipe(zlib.createGunzip()).pipe(rs); break; case 'deflate': res.headers['content-encoding'] = null; this.pipe(zlib.createInflate()).pipe(rs); break; default: this.pipe(rs); break; } dup.emit('response', res); }) var dup = duplex ? duplexer(ws, rs) : rs; if (cb) { dup.on('error', cb); dup.on('response', function (res) { cb.call(dup, null, res); }); } return dup; }
getRemote(function (err, remote) { if (err) return console.error(err); var uri = remote.replace(/\.git$/, '') + '/_/useradd/' + user ; hyperquest(uri).pipe(concat(function (buf) { var token = String(buf); if (!/^\w+\s*$/.test(token)) return console.log(token); var u = url.parse(remote); console.log(u.protocol + '//' + encodeURIComponent(user) + ':' + encodeURIComponent(token.trim()) + '@' + u.host + u.pathname ); })); });
dj: function(key, cb) { var params = { id: key, csrf_token: '' } var req = hyperquest({ uri: API.dj + '?' + qs.stringify(params), headers: HEADERS }).pipe(concat(function(data) { return cb(null, JSON.parse(data)) })) req.on('error', function(err) { return cb(err) }) },
exports.handler = function(stream, data, token) { if (data.project) { data.project.token = token; dal.getProject(token, data.project, stream, function(err, data) { // TODO handle error properly. if (err) return stream.write({ page: 'project', error: err }); data.org = config.org; stream.write({ page: 'project', project: data }); }); } if (data.remove) { return dal.removeProject(token, data.remove, function(err) { stream.write({ page: 'project', remove: err.message }); }); } if (data.repo) { q(data.repo.url, function(err, res) { if (err) { data.error = err; return stream.write(data); } dal.addRepository(data.repo, function(err) { if (err) { data.error = err.message; return stream.write(data); } data.status = res.headers.status; stream.write(data); }); }); } };
function fetch (options, callback) { var url = 'http://' + (options.hostname || 'isaacs.iriscouch.com') + ':' + (options.port || 80) + '/registry/_design/app/_view/updated?include_docs=true&startkey=' + JSON.stringify(options.startTime) hyperquest(url).pipe(bl(function (err, data) { if (err) return callback(err) try { callback(null, JSON.parse(data.toString())) } catch (ex) { callback(new Error('error parsing response data', ex)) } })) }
S3Tasks.prototype.stream = function(url, path, callback) { var self = this; var http_req = hyperquest(url) .on("error", callback) .on("response", function(http_res) { self.emit("info", "GET " + url + " returned HTTP " + http_res.statusCode); if (http_res.statusCode !== 200) { var err = new Error("GET " + url + " returned HTTP " + http_res.statusCode); err.url = url; err.method = "GET"; err.status_code = http_res.statusCode; return callback(err); } var headers = { "Content-Length": http_res.headers["content-length"], "Content-Type": http_res.headers["content-type"] }; if (http_res.headers["content-md5"]) { headers["Content-MD5"] = http_res.headers["content-md5"]; } var s3_req = self.client.put(path, headers) .on("error", callback) .on("response", function(s3_res) { self.emit("info", "PUT " + self.client.url(path) + " returned HTTP " + s3_res.statusCode); if (s3_res.statusCode !== 200) { var err = new Error("PUT " + self.client.url(path) + " returned HTTP " + s3_res.statusCode); err.url = self.client.url(path); err.method = "PUT"; err.status_code = s3_res.statusCode; return callback(err); } callback(); }); http_req.pipe(s3_req); }); return this; };
NpmProxy.prototype.standardWriteUrl = function (pkg, policy, callback) { // // Always default to a set policy. This enables the // the enterprise case only one policy enforced. // policy = policy || this.policy; var writeOk = this.writePrivateOk, self = this, err; // // There **IS NO WHITELIST** so if it is already a known private package // or part of a blacklist then proxy directly to the private npm. // if (policy.private[pkg] || policy.blacklist[pkg]) { return callback(null, policy.npm); } // // Otherwise we need to look this package in the public registry // - if it does not exist we proxy to the private registry // - if it does exist then we proxy to the public registry // hyperquest({ uri: url_.resolve(this.writeNpm.href, pkg), rejectUnauthorized: this.secure }) .on('error', callback) .on('response', function (res) { if (res.statusCode == 404) { if (writeOk) { err = writeOk(policy, self); if (err) { return callback(err); } } policy.private[pkg] = true; return callback(null, policy.npm); } return callback(null, self.writeNpm); }); };
function search (options) { var tracks = [] hyperquest(options.uri) .pipe(JSONStream.parse(options.parsingKeys)) .pipe(through.obj(function toTrack (track, enc, cb) { if (tracks.length < maxResults) { track = options.parseTrack(track) if (track) { tracks.push(track) } } cb() }, end) ) function end () { options.callback(tracks) } }
function afterPasswordRead (err, _pass) { if (err) return callback(err) pass = _pass // Check for 2FA. This triggers an SMS if needed var reqOptions = { headers : { 'User-Agent' : options.userAgent || defaultUA } , method : 'post' , auth : user + ':' + pass } , authUrl = options.authUrl || defaultAuthUrl hyperquest(authUrl, reqOptions, after2FaResponse).end(); }
connected(server, port, function(e) { if (e) { throw err; } console.log('\n--------------------'); console.log('BEFORE\n--------------------\n'); console.log(fs.readFileSync(__dirname + '/page.html', 'utf8')); console.log('\n--------------------'); console.log('AFTER\n--------------------\n'); var request = hyperquest('http://localhost:' + port); request.on('end', function() { server.close(); }); request.pipe(process.stdout); });
cache.get(target, opts, (cacheData) => { // if we have cache data then add the if-none-match header if (cacheData.etag) { requestOpts.headers = { 'If-None-Match': cacheData.etag }; } // if we have cache data and prefer local is set, then return that data if (opts.preferLocal && cacheData.data) { return callback(null, cacheData.data); } debug(`requesting resource: ${targetUrl}, for target: ${target}`); request(requestOpts) // handle the response .on('response', (res) => { let body = ''; debug(`received response for target: ${target}`); // if cached, then return the catched content if (reStatusCached.test(res.statusCode)) { return callback(null, cacheData.data, true); } // otherwise, if not ok, then return an error if (!reStatusOK.test(res.statusCode)) { return callback(`${new Error(((res.headers || {}).status || 'Not found'))}: ${targetUrl}`); } // otherwise, proceed to download the content res.on('data', (buffer) => { body += buffer.toString('utf8'); }); res.on('end', () => { cache.update(target, opts, null, res, body, () => { callback(null, body); }); }); }) .on('error', callback); });