src/cache/client/npm/vuln-regex-detector-client.js
function promiseResult (options, data) {
		log(`promiseResult: data ${data}`);
		return new Promise((resolve, reject) => {
			/* Check cache to avoid I/O. */
			const cacheHit = checkCache(config, pattern);
			if (cacheHit !== RESPONSE_UNKNOWN) {
				log(`Cache hit: ${cacheHit}`);
				return resolve(cacheHit);
			}

			const req = https.request(options, (res) => {
				res.setEncoding('utf8');

				let response = '';
				res.on('data', (chunk) => {
					log(`Got data`);
					response += chunk;
				});

				res.on('end', () => {
					log(`end: I got ${JSON.stringify(response)}`);

					const result = serverResponseToRESPONSE(response);
					log(`end: result ${result}`);
					updateCache(config, postObject.pattern, result);

					if (result === RESPONSE_INVALID) {
						return reject(result);
					} else {
						return resolve(result);
					}
				});
			});

			req.on('error', (e) => {
				log(`Error: ${e}`);
				return reject(RESPONSE_INVALID);
			});

			// Write data to request body.
			log(`Writing to req:\n${data}`);
			req.write(data);
			req.end();
		});
	}
function promiseResult (options, data) {
		log(`promiseResult: data ${data}`);
		return new Promise((resolve, reject) => {
			/* Check cache to avoid I/O. */
			const cacheHit = checkCache(config, pattern);
			if (cacheHit !== RESPONSE_UNKNOWN) {
				log(`Cache hit: ${cacheHit}`);
				return resolve(cacheHit);
			}

			const req = https.request(options, (res) => {
				res.setEncoding('utf8');

				let response = '';
				res.on('data', (chunk) => {
					log(`Got data`);
					response += chunk;
				});

				res.on('end', () => {
					log(`end: I got ${JSON.stringify(response)}`);

					const result = serverResponseToRESPONSE(response);
					log(`end: result ${result}`);
					updateCache(config, postObject.pattern, result);

					if (result === RESPONSE_INVALID) {
						return reject(result);
					} else {
						return resolve(result);
					}
				});
			});

			req.on('error', (e) => {
				log(`Error: ${e}`);
				return reject(RESPONSE_INVALID);
			});

			// Write data to request body.
			log(`Writing to req:\n${data}`);
			req.write(data);
			req.end();
		});
	}
function promiseResult ( options , data ) { log ( ` ${ data } ` ) ; return new Promise ( ( resolve , reject ) => { /* Check cache to avoid I/O. */ const cacheHit = checkCache ( config , pattern ) ; if ( cacheHit !== RESPONSE_UNKNOWN ) { log ( ` ${ cacheHit } ` ) ; return resolve ( cacheHit ) ; } const req = https . request ( options , ( res ) => { res . setEncoding ( 'utf8' ) ; let response = '' ; res . on ( 'data' , ( chunk ) => { log ( ` ` ) ; response += chunk ; } ) ; res . on ( 'end' , ( ) => { log ( ` ${ JSON . stringify ( response ) } ` ) ; const result = serverResponseToRESPONSE ( response ) ; log ( ` ${ result } ` ) ; updateCache ( config , postObject . pattern , result ) ; if ( result === RESPONSE_INVALID ) { return reject ( result ) ; } else { return resolve ( result ) ; } } ) ; } ) ; req . on ( 'error' , ( e ) => { log ( ` ${ e } ` ) ; return reject ( RESPONSE_INVALID ) ; } ) ; // Write data to request body. log ( ` \n ${ data } ` ) ; req . write ( data ) ; req . end ( ) ; } ) ; }
Wrapper so we can return a Promise.
Wrapper so we can return a Promise .