Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function urlRewriteProxyRequest (req, res, next) {
var proxiedUrlPartRegExp = /^\/\S+?\/(https?:)/;
if (proxiedUrlPartRegExp.test(req.url) && req.url.indexOf(unchangeableUrlSession) === -1) {
// NOTE: Store the destination URL so we can send it back for testing purposes (see GET xhr-test route).
req.originalUrl = req.url;
var url = req.url.replace(proxiedUrlPartRegExp, '$1');
// NOTE: Create host-relative URL.
var parsedUrl = urlParser.parse(url);
parsedUrl.host = null;
parsedUrl.hostname = null;
parsedUrl.port = null;
parsedUrl.protocol = null;
parsedUrl.slashes = false;
req.url = urlParser.format(parsedUrl);
}
next();
}
function parseUrlIntoDomainTldPort (str) {
let { hostname, port, protocol } = url.parse(str)
if (port == null) {
port = protocol === 'https:' ? '443' : '80'
}
let parsed = _parseDomain(hostname)
// if we couldn't get a parsed domain
if (!parsed) {
// then just fall back to a dumb check
// based on assumptions that the tld
// is the last segment after the final
// '.' and that the domain is the segment
// before that
const segments = hostname.split('.')
function normUrlFromUrl(u) {
// `url.parse('example.com:9999')` is not what you expect. Make sure we
// have a protocol.
if (! /^\w+:\/\// .test(u)) {
u = 'http://' + u;
}
var parsed = url.parse(u);
// Don't want trailing '/'.
if (parsed.pathname.slice(-1) === '/') {
parsed.pathname = parsed.pathname.slice(0, -1);
}
// Drop redundant ports.
if (parsed.port
&& ((parsed.protocol === 'https:' && parsed.port === '443')
|| (parsed.protocol === 'http:' && parsed.port === '80'))) {
parsed.port = '';
parsed.host = parsed.hostname;
}
return url.format(parsed);
}
grunt.registerMultiTask('download', 'Download files.', function() {
var done = this.async(),
src = this.file.src,
dest = this.file.dest,
options = url.parse(this.file.src);
options.headers = {'accept-encoding': 'gzip,deflate'};
fs.stat(dest, function(err, stats) {
if(err)
// Creates intermediate directories if necessary.
grunt.file.write(dest, '');
else
options.headers['If-Modified-Since'] = stats.mtime.toUTCString();
protocol[options.protocol].get(options, function(res) {
if(res.statusCode == 200) {
grunt.log.writeln(src + ' last modified ' +
new Date(res.headers['last-modified']) + '.');
var output = fs.createWriteStream(dest);
switch (res.headers['content-encoding']) {
case 'gzip':
res.pipe(zlib.createGunzip()).pipe(output);
break;
function parseUrl(url) {
var result = {};
var pathname = URL.parse(url).pathname;
if (pathname == '/Content/DocumentView.aspx') {
// http://lamyline.lamy.fr/Content/DocumentView.aspx?params=H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcj
// KasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/In7ROq+v3+Tv2s/avGl/YXO9rJbXi8/e1Ov8F7bZpPnswS/Mpu
// 06K59W08928Xtxmb/JJvR5W7VZ+SpvPtvbvffpL6zqWV4/uf5s5xc28+rqRXZZXGRtUS2fZLVAK2azz+7vPrh/797BL7zM64a+++wni4t82ea/cF5czJ/T/1tpmjVN
// 0ZxUJXXS5Fk9nb/MLvLPvsgush8Uy7wZZ83q3S9cZG2b15+9fv38d38w/Q7/e/L01bfx4+SU/n3++ifo389PX52+op8vntE/T1+9PH5DP1995yX/eXL2k/jr6TH+ev
// X8hP99esY/5BO0fvL0FB99+fInvjrGx0/w4dMv8M7z1y++g05enb44ff4cvT59+W3F7PfKrz97dfqTZ6/fHP/CcvmW6Peax8JD/H8AN3adcXcBAAA=WKE
result.rtype = 'ARTICLE';
result.mime = 'HTML';
} else if (pathname == '/Content/PageViewPDF.aspx') {
// http://lamyline.lamy.fr/Content/PageViewPDF.aspx?params=H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcj
// KasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/In7ROq+v3+Tv2s/avGl/YXO9rJbXi8/e1Ov8F7bZpPnswS/M
// pu06K59W08928Xtxmb/JJvR5W7VZ+SpvPtvbvffpL6zqWV4/uf5s5xc28+rqRXZZXGRtUS2fZLVAK2azz+7vPrh/797BL7zM64a+++wni4t82ea/cF5czJ/T/1tp
// mjVN0ZxUJXXS5Fk9nb/MLvLPvsgush8Uy7wZZ83q3S9cZG2b15+9fv38d38w/Q7/e/L01bfx4+SU/n3++ifo389PX52+op8vntE/T1+9PH5DP1995yX/eXL2k/jr
// 6TH+evX8hP99esY/5BO0fvL0FB99+fInvjrGx0/w4dMv8M7z1y++g05enb44ff4cvT59+W3F7PfKrz97dfqTZ6/fHP/CcvmW6Peax8JD/H8AN3adcXcBAAA=WKE
function serve(request, response) {
var accept = request.headers.accept
if (request.method === 'OPTIONS') {
return serveCors(request, response)
}
var path = url.parse(request.url).path
if (path &&
path.indexOf('/static/') === 0 &&
(request.method === 'GET' ||
request.method === 'HEAD' ||
request.method === 'OPTIONS')) {
return staticServlet.handleRequest(request, response)
}
if (!accept || _s.startsWith(accept, 'application/json')) {
return serverJson(request, response)
} else if (accept && _s.startsWith(accept, 'application/hal+json')) {
return serverHalJson(request, response)
} else {
return serve406(request, response)
}
function createSessionStore() {
var authObject;
if ('production' == config.get('env')) {
var parsedUrl = url.parse(config.get('redis.url'));
authObject = {
prefix: config.get('redis.session.prefix'),
host: parsedUrl.hostname,
port: parsedUrl.port,
db: config.get('redis.db'),
pass: parsedUrl.auth ? parsedUrl.auth.split(":")[1] : null,
secret: config.get('session.secret')
};
return new RedisStore(authObject);
} else {
return (new session.MemoryStore());
}
};
var htServer = http.createServer(function (req, res) {
var urlp = url.parse(req.url)
var uri = urlp.pathname
if (uri in genericFiles) {
res.writeHead(200, {"Content-Type": genericFiles[uri][1]})
res.write(genericFiles[uri][0])
} else if (uri == '/') {
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"})
res.write(indexPage)
} else if (uri.indexOf('/css') == 0) {
var file = uri.split("/").reverse()[0]
if (file in cssPage) {
res.writeHead(200, {"Content-Type": "text/css; charset=utf-8"})
res.write(cssPage[file])
} else {
res.writeHead(404, {"Content-Type": "text/html; charset=utf-8"})
res.write(uri + " doesn't exist")
function request_noti_http(nu, ri, bodyString, bodytype, xm2mri) {
var bodyStr = '';
var options = {
hostname: url.parse(nu).hostname,
port: url.parse(nu).port,
path: url.parse(nu).path,
method: 'POST',
headers: {
'X-M2M-RI': xm2mri,
'Accept': 'application/' + bodytype,
'X-M2M-Origin': usecseid,
'Content-Type': 'application/' + bodytype,
'Content-Length' : bodyString.length //, for cert
//'X-M2M-RVI': uservi
//
}
};
function response_noti_http(res) {
res.on('data', function (chunk) {
bodyStr += chunk;
});
public getUrl() {
if (this.cachedUrl !== this.url) {
this.cachedUrlObject = url.parse(this.url, true)
this.cachedUrl = this.url
}
return this.cachedUrlObject
}
public href() {