title: Angular 6 - HttpInterceptors - HttpResponse body not getting modified
body: <p>I'm just implementing <code>HttpInterceptor</code>, where i would like to <code>base64</code> encode the request body and <code>base64</code> decode the response body. </p>
  
  <ul>
  <li>Method : HTTP Post Request / Response </li>
  <li>data format : json (this should
  be encoded / decoded)</li>
  </ul>
  
  <p>Here is the code that i have done. When i debug it, the decoded data (i.e) json is being set back into <code>event.body</code>. but, it is not getting received in the services, that actually makes the http call</p>
  
  <pre><code>@Injectable()
  export class Base64Interceptor implements HttpInterceptor {
  
      constructor(private base64UtilService: Base64UtilService) {
  
      }
  
      intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
          let requestClone = request.clone(
              {
                  body: this.base64UtilService.encode(JSON.stringify(request.body)),
                  responseType: 'text'
              }
          )
          return next.handle(requestClone).pipe(tap(event =&gt; {
              if (event instanceof HttpResponse) {
                  debugger;
                  let decodedData = this.base64UtilService.decode(event.body);
                  event = event.clone({
                      body: decodedData
                  });
                  return event;
              }
          },
              (err: any) =&gt; {
                  if (err instanceof HttpErrorResponse) {
                      console.log(err);
                  }
              }))
      }
  
  }
  </code></pre>
  
  <p>I'm just getting the same response that actually comes from the server, the decoding of the <code>event.body</code> is not reflecting. Thanks for the time</p>
  
  <p>This is how the http call is made</p>
  
  <pre><code> sendActivationRequest(url: string, request: MyRequest): Observable&lt;MyResponse&gt; {
          return this.httpClient.post&lt;MyResponse&gt;(url, request)
            .pipe(map((response: MyResponse) =&gt; {
              return response;
            }), catchError((error) =&gt; {
              return throwError(error);
            }));
        }
  </code></pre>