mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #3152 from alanorth/client-user-agent
Forward client's user-agent instead of Node's
This commit is contained in:
@@ -18,6 +18,14 @@ export class ForwardClientIpInterceptor implements HttpInterceptor {
|
|||||||
*/
|
*/
|
||||||
intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
const clientIp = this.req.get('x-forwarded-for') || this.req.connection.remoteAddress;
|
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 }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user