Every line of 'npm set proxy' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
25 function setProxy(){ 26 if(proxyMode == 1){ 27 var config = { 28 mode: "pac_script", 29 pacScript: { 30 data: 'function FindProxyForURL(url, host) { return "' + setting.proxy + '"; }' 31 } 32 }; 33 chrome.proxy.settings.set({value: config, scope: 'regular'}, function(){}); 34 chrome.browserAction.setBadgeText({text:'ALL'}); 35 chrome.browserAction.setBadgeBackgroundColor({ color: [255, 128, 64, 255] }); 36 }else if(proxyMode == -1){ 37 var config = { mode: "direct" }; 38 chrome.proxy.settings.set({value: config, scope: 'regular'}, function(){}); 39 chrome.browserAction.setBadgeText({text:'OFF'}); 40 chrome.browserAction.setBadgeBackgroundColor({ color: [128, 128, 128, 128] }); 41 }else{ 42 var config = { 43 mode: "pac_script", 44 pacScript: { 45 data: currentPacFile 46 } 47 }; 48 chrome.proxy.settings.set({value: config, scope: 'regular'}, function(){}); 49 chrome.browserAction.setBadgeText({text:''}); 50 } 51 }
18 function Proxy(config) { 19 this.port = config.port; 20 this.proxyPort = config.proxyPort; 21 this.domain = config.domain; 22 if (config.basicAuth) { 23 var basicAuth = config.basicAuth.split(':'); 24 this.basicAuth = {}; 25 this.basicAuth.username = basicAuth[0]; 26 this.basicAuth.password = basicAuth[1]; 27 } 28 this.headers = config.headers; 29 this.limit = config.limit; 30 this.blacklist = config.blacklist; 31 this.blacklistStatus = config.blacklistStatus; 32 this.blacklistMethod = config.blacklistMethod; 33 this.proxySleepBeforeStart = config.proxySleepBeforeStart; 34 35 this.log = logger.getLog(); 36 this.proxyLog = logger.addLog('browsermobproxy', { 'silent': true, 'logDir': config.logDir }); 37 }
15 static async unsetProxy() { 16 throw new Error('You have to implement the method unsetProxy!'); 17 }
3 export default function createBaseProxy(): httpProxy { 4 const proxy = httpProxy.createProxyServer({ 5 prependUrl: false 6 } as httpProxy.ServerOptions); 7 8 proxy.on("error", function(err: any, req: any, res: any) { 9 res.writeHead(500, { 10 "Content-Type": "text/plain" 11 }); 12 13 console.error(err); 14 15 res.end("Something went wrong."); 16 }); 17 18 proxy.on("proxyRes", function(proxyRes, req, res) { 19 // Add a default cache time of 60 seconds on GETs so the CDN can cache in times of high load. 20 if ( 21 req.method === "GET" && 22 !proxyRes.headers["Cache-Control"] && 23 !proxyRes.headers["cache-control"] && 24 !req.headers["Cache-Control"] && 25 !req.headers["cache-control"] 26 ) { 27 proxyRes.headers["Cache-Control"] = "public, max-age=60"; 28 } 29 /** 30 * Remove security sensitive headers 31 * `server` header is from scala APIs 32 * Proxied content has to be filtered from here 33 * while other content (produced locally by gateway) has been 34 * taken care of by `app.disable("x-powered-by");` in index.js 35 */ 36 Object.keys(proxyRes.headers).forEach(headerKey => { 37 const headerKeyLowerCase = headerKey.toLowerCase(); 38 if ( 39 headerKeyLowerCase === "x-powered-by" || 40 headerKeyLowerCase === "server" 41 ) { 42 proxyRes.headers[headerKey] = undefined; 43 } 44 }); 45 }); 46 47 return proxy; 48 }
4 export function setProxy(proxyCfg: task.ProxyConfiguration) { 5 const proxy = new URL(proxyCfg.proxyUrl); 6 const proxyEnvVarName: string = proxy.protocol === 'https:'? "https_proxy" : "http_proxy"; 7 8 if (proxyCfg.proxyUsername) { 9 proxy.username = proxyCfg.proxyUsername; 10 } 11 if (proxyCfg.proxyPassword) { 12 task.setSecret(qs.escape(proxyCfg.proxyPassword)); 13 proxy.password = proxyCfg.proxyPassword; 14 } 15 16 task.setVariable(proxyEnvVarName, proxy.toString()); 17 }