-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Basically theres a workaround you can use in JS that works with the agent options settings in the node request library that allows you to dynamically inject ca bundles straight to the context.route.EventHandler
I've tried to find out if this can work using urllib request but I can't seem to find a plausible way to do it
Could you guys please advise?
Heres the work around from the JS version
const fs = require('fs');
const request = require('request');
const browser = await chromium.launch();
const ctx = await browser.newContext();
await ctx.route('**/*', (route, req) => {
const options = {
uri: req.url(),
method: req.method(),
headers: req.headers(),
body: req.postDataBuffer(),
timeout: 10000,
followRedirect: false,
agentOptions: {
ca: fs.readFileSync('./certs/ca.pem'),
pfx: fs.readFileSync('./certs/user_cert.p12'),
passphrase: fs.readFileSync('./certs/user_cert.p12.pwd'),
},
};
let firstTry = true;
const handler = function handler(err, resp, data) {
if (err) {
/* Strange random connection error on first request, do one re-try */
if (firstTry) {
firstTry = false;
return request(options, handler);
}
console.error(`Unable to call ${options.uri}`, err.code, err);
return route.abort();
} else {
return route.fulfill({
status: resp.statusCode,
headers: resp.headers,
body: data,
});
}
};
return request(options, handler);
});