request .get(url.href) .on('response', (resp) => { resp.on('data', (chunk) => { if(image.size > MAX_FILE_SIZE + 1024*10) { // maxFileSize + 10KB padding. isMaxFileSizeExceed = true; .on('end', () => { if(isResponseSent) return; if(isMaxFileSizeExceed) .on('error', (err) => { log.error(err, 'Error uploading file'); return errors.internalServer(res); }) .on('finish', async () => { const metadata = await gcsFile.getMetadata(); await gcsFile.makePublic();
request.get({ url: url, }, function(err, res, body) { if (err) { console.log(err); } }).on('response', function(response) { var bufferhelper = new BufferHelper(); response.on('data', function(chunk) { bufferhelper.concat(chunk); }); response.on('end', function() { var result = iconv.decode(bufferhelper.toBuffer(), 'UTF-8'); console.log("---------- Test NLU API, api = "+ apiName +" ----------"); console.log("Sending 'POST' request to URL : " + url); console.log("Result:\n" + result); console.log("------------------------------------------"); }); });
req.on('response', function(res) { res.setEncoding('utf8'); var responseData = ''; var status = res.statusCode; var headers = res.headers; res.on('data', function(chunk) { responseData += chunk; }); res.on('end', function() { res.destroy(); if (headers['content-type'] && headers['content-type'].indexOf('application/json') !== -1) { try { responseData = JSON.parse(responseData); } catch (error) { return done(error); } } done(null, responseData, status, headers); }); });
async function fetchFromRemote(url, outputFileName) { // Fetch console.log(`Downloading ${url}`) await fs.ensureDir(path.parse(outputFileName).dir) await new Promise((resolve, reject) => { request(url) .on('response', res => { if (res.statusCode >= 400) { return reject(`${version} not found, please input a valid version`) } const len = parseInt(res.headers['content-length'], 10) bar = new ProgressBar('Downloading [:bar] :rate/bps :percent :etas', { width: 20, total: len, renderThrottle: 500, }) res.on('data', chunk => { bar.tick(chunk.length) }) }) .on('error', reject) .on('end', resolve) .pipe(fs.createWriteStream(outputFileName)) }) }
const req = request(opts); req.on('response', (res) => { if (res.statusCode !== 200) { resolve('http error'); res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { resolve(data); }); }); req.on('error', (error) => { if (error.code === 'CircuitBreakerOpenException') { resolve('circuit breaking');
httpStream.on('response', function(response) { var request = this, len = 0; convertStream(response, req, res, hint); response.on('data', function (chunk) { len += chunk.length; if (!abort && len > convert.maxConversionSize) { response.on('end', function() { console.log('Convert: received file of ' + len + ' bytes' + (abort ? ' (which we\'re discarding).' : '.')); });
req.on('error', done) req.on('response', function (res) { if (res.statusCode !== 200) { done(new Error(res.statusCode + ' status code downloading checksum')) res.on('data', function (chunk) { chunks.push(chunk) }) res.on('end', function () { var lines = Buffer.concat(chunks).toString().trim().split('\n') lines.forEach(function (line) {