Imagine we are developing a response interceptor for an Angular 4 application using the HttpClient
:
export class MyInterceptor implements HttpInterceptor {
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).map((event: HttpEvent<any>) => {
if (!(event instanceof HttpResponse))
return event;
// Should we clone the event.body before making modifications like: event.body.items = { ... };?
});
}
}
We understand that when implementing a request interceptor, it is necessary to use the clone()
method on the req
object to preserve its immutability.
However, in the case of modifying the payload accessed through the body
property in the response, do we still need to perform a clone()
operation?