Remove unidentified-script user agent when running the API proxy server

This commit is contained in:
Samuel Elliott 2022-08-13 00:40:24 +01:00
parent 0e7b6e50c4
commit f24dc2c63c
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 17 additions and 2 deletions

View File

@ -14,7 +14,7 @@ import { NotificationManager, PresenceEvent, ZncNotifications } from '../../comm
import { product } from '../../util/product.js';
import { parseListenAddress } from '../../util/net.js';
import { AuthPolicy, AuthToken, ZncPresenceEventStreamEvent } from '../../api/znc-proxy.js';
import { addUserAgent } from '../../util/useragent.js';
import { addCliFeatureUserAgent } from '../../util/useragent.js';
import { ErrorResponse } from '../../api/util.js';
declare global {
@ -54,7 +54,7 @@ export function builder(yargs: Argv<ParentArguments>) {
type Arguments = YargsArguments<ReturnType<typeof builder>>;
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
addUserAgent('http-server');
addCliFeatureUserAgent('http-server');
const storage = await initStorage(argv.dataPath);

View File

@ -17,6 +17,21 @@ export function addUserAgent(...useragent: string[]) {
additional_useragents.push(...useragent);
}
/**
* Only used by cli/nso/http-server.ts.
* This command is intended to be run automatically and doesn't make any requests itself, so this function removes
* the unidentified-script user agent string.
*/
export function addCliFeatureUserAgent(...useragent: string[]) {
if (additional_useragents[0] === 'nxapi-cli' && additional_useragents[1] === 'unidentified-script') {
additional_useragents.splice(1, 1, ...useragent);
} else if (additional_useragents[0] === 'nxapi-cli') {
additional_useragents.splice(1, 0, ...useragent);
} else {
additional_useragents.splice(0, 0, ...useragent);
}
}
let warned_no_useragent = false;
export function getUserAgent(additional = getAdditionalUserAgents()) {