1
0

src/app/core: forward client user-agent

Forward the client's user-agent instead of sending Node's.
This commit is contained in:
Alan Orth
2024-06-28 07:58:15 +03:00
parent 735a3af254
commit 5b2966cf48

View File

@@ -18,6 +18,14 @@ export class ForwardClientIpInterceptor implements HttpInterceptor {
*/
intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const clientIp = this.req.get('x-forwarded-for') || this.req.connection.remoteAddress;
return next.handle(httpRequest.clone({ setHeaders: { 'X-Forwarded-For': clientIp } }));
const headers = { 'X-Forwarded-For': clientIp };
// if the request has a user-agent retain it
const userAgent = this.req.get('user-agent');
if (userAgent) {
headers['User-Agent'] = userAgent;
}
return next.handle(httpRequest.clone({ setHeaders: headers }));
}
}