describe('safeParseURL()', () => { it('should return null if url invalid', () => { assert(utils.safeParseURL('https://eggjs.org%0a.com') === null); assert(utils.safeParseURL('/path/for') === null); }); it('should return parsed url', () => { assert(utils.safeParseURL('https://eggjs.org').hostname === 'eggjs.org'); assert(utils.safeParseURL('https://eggjs.org!.foo.com').hostname === 'eggjs.org!.foo.com'); }); });
function checkOrigin(origin, callback) { // origin is allowed if ( typeof origin === 'undefined' || `.${new URL(origin).hostname}`.endsWith(`.${schnack_domain}`) ) { return callback(null, true); } callback(new Error('Not allowed by CORS')); }
function getSchnackDomain() { const schnack_host = config.get('schnack_host'); try { const schnack_url = new URL(schnack_host); if (schnack_url.hostname === 'localhost') { return schnack_url.hostname; } else { const schnack_domain = schnack_url.hostname .split('.') .slice(1) .join('.'); return schnack_domain; } } catch (error) { console.error( `The schnack_host value "${schnack_host}" doesn't appear to be a proper URL. Did you forget "http://"?` ); process.exit(-1); } }
const urlParser = ( req, res, next ) => { if ( !req.isRoutable ) return next( false ); const urlObject = new URL( req.headers.url ); /** * url query variables convert to object * ?a=b&c=d --> {a: b, c: d} */ urlObject.searchParams.forEach( ( value, name ) => { req.query[ name ] = value; } ); req.pathname = urlObject.pathname; req.hostname = urlObject.hostname; req.href = urlObject.href; return next( true ); }
return this._ensureConnection(remotePeerAddress) case 'holorelay:': return this._ensureCIdForPeerAddress(uri.hostname) default: throw new Error('unhandled peerTransport protocol ' + uri.protocol)
const host = parsed.hostname.replace(/[[\]]/g, '') const path = parsed.pathname
hostname: _url.hostname, port: _url.port, path: `${_url.pathname}${_url.search}`,
const metricName = options.metricName || url.hostname + '.response' const requestMetricTags = [ `method:${method}`,
log.debug('creating new tcp connection', addr) const url = new URL(addr) const conn = net.connect(url.port, url.hostname) conn.setNoDelay(true) conn.setKeepAlive(true)
const _url = new URL(url); const options = { hostname: _url.hostname, port: _url.port, path: `${_url.pathname}${_url.search}`, if (res.statusCode > 300 && res.statusCode < 400 && res.headers.location) { const redirUrl = new URL(res.headers.location); if(!redirUrl.hostname) {// partial URL const origUrl = new URL(url); redirUrl.hostname = origUrl.hostname; redirUrl.protocol = origUrl.protocol;
const _url = new URL(url); const options = { hostname: _url.hostname, port: _url.port, path: `${_url.pathname}${_url.search}`, if (res.statusCode > 300 && res.statusCode < 400 && res.headers.location) { const redirUrl = new URL(res.headers.location); if(!redirUrl.hostname) {// partial URL const origUrl = new URL(url); redirUrl.hostname = origUrl.hostname; redirUrl.protocol = origUrl.protocol;
log.debug('creating new tcp connection', addr) const url = new URL(addr) const conn = net.connect(url.port, url.hostname) conn.setNoDelay(true) conn.setKeepAlive(true)
const metricName = options.metricName || url.hostname + '.response' const requestMetricTags = [ `method:${method}`,