const downloadFileFromURI = uri => { return new Promise((res, rej) => { http.get(uri, response => { response.setDefaultEncoding('base64'); let body = `data:${response.headers['content-type']};base64,`; response.on('data', data => body += data); response.on('end', () => res(body)); }).on('error', e => { rej(`Error downloading file from ${uri}: ${e.message}`); }); }); }
var proxy = function (request, response) { var req = http.request(request.url + (request.url.indexOf('?') == -1 ? '?' : '&') + 'proxy=' + request.socket.localPort); req.addListener('response', function (res) { res.addListener('data', function (chunk) { response.write(chunk, 'binary'); }); res.addListener('end', function () { response.end(); }); response.writeHead(res.statusCode, res.headers); }); request.addListener('data', function (chunk) { req.write(chunk, 'binary'); }); request.addListener('end', function () { req.end(); }); }
http.createServer(function (req, res) { var url = URL.parse(req.url, true), uri = decodeURIComponent(url.pathname), postData = ''; if (paths[uri] !== undefined) { if (req.method === 'POST') { req.on('data', function (chunk) { postData += chunk.toString(); }); req.on('end', function () { if (!req.headers['content-type'] || req.headers['content-type'].indexOf('multipart') !== 0) postData = qs.parse(postData); paths[uri](url, req, res, postData); }); } else { paths[uri](url, req, res); } } else { res.writeHead(404); res.end(); } })
// Retrieve Google Signin Keys (with cache control) function getGoogleKeyByKeyId(keyId) { if (cache[keyId] && cache.expiresAt > new Date()) { return cache[keyId]; } return new Promise((resolve, reject) => { https.get(`https://www.googleapis.com/oauth2/v3/certs`, res => { let data = ''; res.on('data', chunk => { data += chunk.toString('utf8'); }); res.on('end', () => { const {keys} = JSON.parse(data); const pems = keys.reduce((pems, {n: modulus, e: exposant, kid}) => Object.assign(pems, {[kid]: rsaPublicKeyToPEM(modulus, exposant)}), {}); if (res.headers['cache-control']) { var expire = res.headers['cache-control'].match(/max-age=([0-9]+)/); if (expire) { cache = Object.assign({}, pems, {expiresAt: new Date((new Date()).getTime() + Number(expire[1]) * 1000)}); } } resolve(pems[keyId]); }); }).on('error', reject); }); }
this.redirector = http.createServer((req, res) => { res.writeHead(301, { Location: `https://${req.headers.host.split(':')[0]}:${TLS_PORT}${req.url}` }); res.end();
method: "GET", port:objUrl.port?objUrl.port:80, headers:opt.headers rejectUnauthorized: false, requestCert: true, headers:opt.headers if(res3.statusCode==302) handleCookieIfNecessary(opt1,res3.headers); opt.headers.cookie=opt1.headers.cookie; redirect(res,bHttps,opt,res3.headers.location) var resHeader=filterResHeader(res3.headers) resHeader["doclever-request"]=JSON.stringify(handleSelfCookie(req3)); res.writeHead(res3.statusCode,resHeader);
function proxy(req,res) { var bHttps=false; if(req.headers["url-doclever"].toLowerCase().startsWith("https://")) path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req), path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req) if(res2.statusCode==302) redirect(res,bHttps,opt,res2.headers.location) var resHeader=filterResHeader(res2.headers,res) resHeader["doclever-request"]=JSON.stringify(handleSelfCookie(req2)); res.writeHead(res2.statusCode, resHeader);
function proxy(req,res) { var bHttps=false; if(req.headers["url-doclever"].toLowerCase().startsWith("https://")) path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req), path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req) if(res2.statusCode==302) redirect(res,bHttps,opt,res2.headers.location) var resHeader=filterResHeader(res2.headers,res) resHeader["doclever-request"]=JSON.stringify(handleSelfCookie(req2)); res.writeHead(res2.statusCode, resHeader);
function proxy(req,res) { var bHttps=false; if(req.headers["url-doclever"].toLowerCase().startsWith("https://")) path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req), path: req.headers["path-doclever"], method: req.headers["method-doclever"], headers: getHeader(req), port:getPort(req) if(res2.statusCode==302) redirect(res,bHttps,opt,res2.headers.location) var resHeader=filterResHeader(res2.headers,res) resHeader["doclever-request"]=JSON.stringify(handleSelfCookie(req2)); res.writeHead(res2.statusCode, resHeader);