/**
 * Get server response observable by sending request to `next()`.
 * Will add the response to the cache on the way out.
 */
function sendRequest(
  req: HttpRequest,
  next: HttpHandler,
  cache: RequestCache): Observable> {
 
  // No headers allowed in npm search request
  const noHeaderReq = req.clone({ headers: new HttpHeaders() });
 
  return next.handle(noHeaderReq).pipe(
    tap(event => {
      // There may be other events besides the response.
      if (event instanceof HttpResponse) {
        cache.put(req, event); // Update the cache.
      }
    })
  );
}