0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-01 02:42:23 -05:00

feat: user agent is the client by default (#2793)

* feat: user agent is the client by default

* chore: get user agent fix

* chore: disable x-powered-by
This commit is contained in:
Juan Picado 2021-12-21 23:09:31 +01:00 committed by GitHub
parent 46e583f683
commit e5d79ce8f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View file

@ -30,10 +30,14 @@ const defineAPI = function (config: IConfig, storage: IStorageHandler): any {
// Router setup
app.use(log(config));
app.use(errorReportingMiddleware);
app.use(function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
res.setHeader('X-Powered-By', config.user_agent);
next();
});
if (config.user_agent) {
app.use(function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
res.setHeader('X-Powered-By', config.user_agent);
next();
});
} else {
app.disable('x-powered-by');
}
app.use(compression());

View file

@ -4,12 +4,7 @@ import _ from 'lodash';
import { PackageList, Config as AppConfig, Security, Logger } from '@verdaccio/types';
import { MatchedPackage, StartUpConfig } from '../../types';
import { generateRandomHexString } from './crypto-utils';
import {
getMatchedPackagesSpec,
normalisePackageAccess,
sanityCheckUplinksProps,
uplinkSanityCheck
} from './config-utils';
import { getMatchedPackagesSpec, normalisePackageAccess, sanityCheckUplinksProps, uplinkSanityCheck } from './config-utils';
import { getUserAgent, isObject } from './utils';
import { APP_ERROR } from './constants';
@ -22,6 +17,7 @@ const allowedEnvConfig = ['http_proxy', 'https_proxy', 'no_proxy'];
*/
class Config implements AppConfig {
public logger: Logger;
// @ts-ignore
public user_agent: string;
// @ts-ignore
public secret: string;
@ -49,7 +45,7 @@ class Config implements AppConfig {
}
// @ts-ignore
if (_.isNil(this.user_agent)) {
if (config?.user_agent) {
this.user_agent = getUserAgent();
}

View file

@ -278,7 +278,7 @@ class ProxyStorage implements IProxy {
headers[accept] = headers[accept] || contentTypeAccept;
headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';
// registry.npmjs.org will only return search result if user-agent include string 'npm'
headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;
headers[userAgent] = this.userAgent ? `npm (${this.userAgent})` : options.req?.get('user-agent');
return this._setAuth(headers);
}