Commits

Tim Donohue authored and GitHub committed 6610ccc8c1f Merge
Merge pull request #3157 from DSpace/backport-3152-to-dspace-8_x

[Port dspace-8_x] Forward client's user-agent instead of Node's
No tags
gidlmaster

src/app/core/forward-client-ip/forward-client-ip.interceptor.ts

Modified
20 20 constructor(@Inject(REQUEST) protected req: any) {
21 21 }
22 22
23 23 /**
24 24 * Intercept http requests and add the client's IP to the X-Forwarded-For header
25 25 * @param httpRequest
26 26 * @param next
27 27 */
28 28 intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
29 29 const clientIp = this.req.get('x-forwarded-for') || this.req.connection.remoteAddress;
30 - return next.handle(httpRequest.clone({ setHeaders: { 'X-Forwarded-For': clientIp } }));
30 + const headers = { 'X-Forwarded-For': clientIp };
31 +
32 + // if the request has a user-agent retain it
33 + const userAgent = this.req.get('user-agent');
34 + if (userAgent) {
35 + headers['User-Agent'] = userAgent;
36 + }
37 +
38 + return next.handle(httpRequest.clone({ setHeaders: headers }));
31 39 }
32 40 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut