In Angular 2 I am trying to control http request/response to set/read some headers when sending request and getting response.
I just override HttpRequest like this, and it is working for me :
@Injectable()
export class HttpRequest extends RequestOptions {
constructor() {
super({
method: RequestMethod.Get,
headers: new Headers({
'X-Some-Header': 'some-content'})
});
}
}
But for overriding Response I have problem :
@Injectable()
export class HttpResponse extends Response {
constructor(responseOptions: ResponseOptions) {
super(responseOptions);
console.log("RESPONSE IS CREATED!!!!!!!");
}
}
The constructor never being called and here it is the bootstrap:
bootstrap(AppComponent,
[ ROUTER_PROVIDERS
,HTTP_PROVIDERS
,provide(RequestOptions, {useClass: HttpRequest})
,provide(Response, {useClass: HttpResponse})
]);
The reason for overriding the response is to read some response headers and control for 404-Not Page Found globally and ....
Thanks,