title: Unable to get response header in http interceptor in angular 5
body: <p>I am able to get the token from local storage after signin. After that I need to get the token from the header response as I need to store the new token again before the earlier one gets expired.</p>
  
  <p>Below is my intercept file:</p>
  
  <pre><code>    import { environment } from './../../environments/environment';
      import { Injectable, Inject } from '@angular/core';
      import {
          HttpRequest,
          HttpHandler,
          HttpEvent,
          HttpInterceptor,
          HttpErrorResponse,
          HttpResponse,
          HttpHeaderResponse,
          HttpClientModule
      } from '@angular/common/http';
      import { Router } from '@angular/router';
      import { Observable } from 'rxjs/Observable';
      import 'rxjs/add/operator/do';
      import 'rxjs/add/operator/catch';
      import 'rxjs/Observable';
      import 'rxjs/add/observable/throw';
      import 'rxjs/add/observable/empty';
  
      @Injectable()
      export class AppHttpInterceptor implements HttpInterceptor {
  
          constructor(private router: Router) { }
  
          intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler): 
          Observable&lt;HttpEvent&lt;any&gt;&gt; {
  
              const token = this.getToken();  //first token after signin
  
              const JWT = `Bearer ${token}`;
              req = req.clone({
                  setHeaders: {
                      Authorization: JWT
                  }
              });
  
              req = req.clone({ url: this.prepareUrl(req.url) });
  
              return next.handle(req)
                  .do((event: HttpEvent&lt;any&gt;) =&gt; {
                      if (event instanceof HttpResponse) {
                          console.log(event);  //here I am checking for a new 
                          token in event but unable to get that.
                      }
                  })
                  .catch((error, caught) =&gt; {
                      //intercept the response error and displace it to the console
                      console.log(error);
  
                      if (error instanceof HttpErrorResponse) {
                          if (error.status === 401) {
                              // redirect to the login route
                              this.router.navigate(['/login']);
                          }
                          else if (error.status === 0) {
                              // Show the error message
                              return Observable.empty&lt;HttpEvent&lt;any&gt;&gt;();
                          }
                      }
  
                      //return the error to the method that called it
                      return Observable.throw(error);
  
  
                  }) as any;
          }
  
  
          private isAbsoluteUrl(url: string): boolean {
              const absoluteHttpPattern = /^http?:\/\//i;
              const absoluteHttpsPattern = /^https?:\/\//i;
              return absoluteHttpPattern.test(url) || absoluteHttpsPattern.test(url);
          }
  
          private prepareUrl(url: string): string {
              url = this.isAbsoluteUrl(url) ? url : environment.api + url;
              return url.replace(/([^:]\/)\/+/g, '$1');
          }
  
          getToken(): string {
              return localStorage.getItem('accessToken');
          }
      }
  </code></pre>
  
  <p>Below is the log response I am getting :</p>
  
  <pre><code>HttpResponsebody: Array[2]headers: HttpHeaderslazyInit: ()lazyUpdate: nullnormalizedNames: Map__proto__: Objectok: truestatus: 200statusText: "OK"type: 4url: null__proto__: HttpResponseBase
  </code></pre>
  
  <p>When I open developer tools I am able to see response headers but its not there in my intercept file.</p>
  
  <pre><code>Cache-Control:no-cache, no-store, max-age=0, must-revalidate
  Content-Type:application/json;charset=UTF-8
  Date:Tue, 11 Dec 2018 13:16:54 GMT
  Expires:0
  Pragma:no-cache
  t:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBuZXRhcHAuY29tIiwic2NvcGVzIjpbeyJhdXRob3JpdHkiOiIxIn1dLCJpc3MiOiJodHRwOi8vY3JvLm5ldGFwcC5jb20iLCJpYXQ (I need to get this "t" value in my intercept file)
  Transfer-Encoding:chunked
  X-Content-Type-Options:nosniff
  X-Frame-Options:DENY
  X-XSS-Protection:1; mode=block
  </code></pre>