Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nonblocking committed Dec 27, 2023
1 parent 340c951 commit 7f75a1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export interface Plugins {
* * streamAPI (based on the Node.js stream API)
* * nodeHttpProxy (based on [node-http-proxy](https://github.com/http-party/node-http-proxy))
* * request (based on the deprecated (!) [request](https://github.com/request/request))
* * default (which is currently nodeHttpProxy)
* * default (which is streamAPI)
*/
proxyImpl?: "default" | "streamAPI" | "nodeHttpProxy" | "request";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {URLSearchParams, URL} from 'url';
import http from 'http';
import https from 'https';
import {pipeline} from 'stream/promises';
import {loggingUtils} from '@mashroom/mashroom-utils';
import {getHttpPool, getHttpsPool, getPoolConfig, getWaitingRequestsForHostHeader} from '../connection-pool';
import {processHttpResponse, processRequest, processWsRequest} from './utils';

Expand All @@ -22,7 +21,6 @@ import type {
MashroomLoggerFactory,
IncomingMessageWithContext
} from '@mashroom/mashroom/type-definitions';
import type {MashroomSecurityService} from '@mashroom/mashroom-security/type-definitions';
import type {HttpHeaders} from '../../type-definitions';

const MAX_RETRIES = 2;
Expand All @@ -32,17 +30,16 @@ const MAX_RETRIES = 2;
*/
export default class ProxyImplNodeStreamAPI implements Proxy {

private readonly _globalLogger: MashroomLogger;
private readonly _requestMetrics: RequestMetrics;
private readonly _wsConnectionMetrics: WSConnectionMetrics;

constructor(private _socketTimeoutMs: number, private _rejectUnauthorized: boolean, private _interceptorHandler: InterceptorHandler,
private _headerFilter: HttpHeaderFilter, private _retryOnReset: boolean,
private _wsMaxConnectionsPerHost: number | null, private _wsMaxConnectionsTotal: number | null,
private _poolMaxWaitingRequestsPerHost: number | null, loggerFactory: MashroomLoggerFactory) {
this._globalLogger = loggerFactory('mashroom.httpProxy');
const logger = loggerFactory('mashroom.httpProxy');
const poolConfig = getPoolConfig();
this._globalLogger.info(`Initializing http proxy with pool config: ${JSON.stringify(poolConfig, null, 2)} and socket timeout: ${_socketTimeoutMs}ms`);
logger.info(`Initializing http proxy with pool config: ${JSON.stringify(poolConfig, null, 2)} and socket timeout: ${_socketTimeoutMs}ms`);
this._requestMetrics = {
httpRequestCountTotal: 0,
httpRequestTargetCount: {},
Expand Down Expand Up @@ -139,9 +136,7 @@ export default class ProxyImplNodeStreamAPI implements Proxy {
}

async forwardWs(req: IncomingMessageWithContext, socket: Socket, head: Buffer, targetUri: string, additionalHeaders: HttpHeaders = {}): Promise<void> {
const securityService: MashroomSecurityService | undefined = req.pluginContext.services.security?.service;
const user = securityService?.getUser(req as Request);
const logger = req.pluginContext.loggerFactory('mashroom.httpProxy').withContext(loggingUtils.userContext(user));
const logger = req.pluginContext.loggerFactory('mashroom.httpProxy');

const {protocol, host} = new URL(targetUri);
if (protocol !== 'ws:' && protocol !== 'wss:') {
Expand Down

0 comments on commit 7f75a1a

Please sign in to comment.