Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlord: Support POP v9 and its finishRockHeaderUpdating command #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
26 changes: 25 additions & 1 deletion src/overlord/Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ export class ProxyOverlord {
console.log("Proxy finished any pending caching transactions");
}

async finishRockHeaderUpdating() {
const options = {
'Overlord-job.type-regex': new RegExp('\\bRock::HeaderUpdater'),
};
await this._remoteCall("/finishJobs", options);
console.log("Proxy finished all HTTP header updating jobs in rock cache_dir(s)");
}

// Wait for the proxy to accumulate exactly the given number of
// not-yet-satisfied requests (containing the given URL path). This only
// works if the proxy can parse request (headers) but cannot satisfy those
Expand Down Expand Up @@ -515,6 +523,22 @@ export class ProxyOverlord {
}

_remoteCall(commandOrString, options) {
if (options) {
// convert RegExp objects to base64-encoded strings
options = Object.fromEntries(Object.entries(options).map(([name, value]) => {
if (name.endsWith('-regex')) {
assert(value instanceof RegExp);
// Store the regex in the 'extended pattern' format, so that Operlord.pl could
// dynamically restore it.
// See https://perldoc.perl.org/perlre#Extended-Patterns for details.
const flags = value.flags ? `(?${value.flags})` : "";
return [name, Buffer.from(`${flags}${value.source}`).toString('base64')];
}
assert(!(value instanceof RegExp));
return [name, value];
}));
}

return new Promise((resolve) => {

const command = ((typeof commandOrString) === 'string') ?
Expand All @@ -526,7 +550,7 @@ export class ProxyOverlord {
host: "127.0.0.1",
port: 13128,
headers: {
'Pop-Version': 8,
'Pop-Version': 9,
},
};

Expand Down