question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

headers.getAll() overload and get all sent headers (with browser defaults) inside HTTP_INTERCEPTORS

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

  • Does not get all headers with .headers.getAll().
  • Does not get all default headers sent when request.headers accessed from enum.sent

Expected behavior

  • Get all headers with .headers.getAll(). Add overload for the same when arguments not provided. Proposal to add .getAll() method overload to get all headers at once.
  • Get all default headers sent when request.headers accessed from enum.sent. Proposal to add all sent headers even browser default headers that can be all fetched with .getAll() overload.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-gitter-dygdrc?file=app%2Finterceptor.service.ts


intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    console.log('Request', request.headers.keys());
    // Proposal to add .getAll() method overload to get all headers at once when no args are provided
    return next
      .handle(request).pipe(
        tap((ev: HttpEvent<any>) => {
          if (ev.type === HttpEventType.Sent) {
            console.log('ReqAfterSent', request.headers);
            // Proposal to add all sent headers even browser default headers that can be all fetched with .getAll() overload
          }
        })
      );
  }

What is the motivation / use case for changing the behavior?

Application use case when working just with headers.

Environment

Angular CLI: 6.1.4 Node: 10.7.0 OS: linux x64 Angular: 6.1.4 … animations, cli, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, router

Package Version

@ angular-devkit/architect 0.7.4 @ angular-devkit/build-angular 0.7.4 @ angular-devkit/build-optimizer 0.7.4 @ angular-devkit/build-webpack 0.7.4 @ angular-devkit/core 0.7.4 @ angular-devkit/schematics 0.7.4 @ angular/cdk 6.4.6 @ angular/material 6.4.6 @ ngtools/webpack 6.1.4 @ schematics/angular 0.7.4 @ schematics/update 0.7.4 rxjs 6.2.2 typescript 2.7.2 webpack 4.9.2

Browser:

  • [X ] Chrome (desktop) version XX
  • [ X] Chrome (Android) version XX
  • [ X] Chrome (iOS) version XX
  • [X ] Firefox version XX
  • [X ] Safari (desktop) version XX
  • [X ] Safari (iOS) version XX
  • [ X] IE version XX
  • [ X] Edge version XX

For Tooling issues: na

Others: NA

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alxhubcommented, Oct 11, 2018

This is an interesting idea - the Sent event could deliver information about the actually sent request, including headers if requested. I’ll think about this.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 31, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to retrieve all request headers via Angular interceptor
Access to headers in market standard browsers is controlled by CORS policies. This answer will help understand it, this is a server side ......
Read more >
XMLHttpRequest.getAllResponseHeaders() - Web APIs | MDN
The XMLHttpRequest method getAllResponseHeaders() returns all the response headers, separated by CRLF, as a string, or returns null if no ...
Read more >
3 ways to use Angular HTTP Interceptors
Angular HTTP Interceptors provide a flexible mechanism to control your application when dealing with network-related resources.
Read more >
Communicating with backend services using HTTP - Angular
In Adding headers, for example, the service set the default headers using the ... using a pipe to send all observables returned by...
Read more >
getallheaders - Manual
getallheaders (): array. Fetches all HTTP headers from the current request. This function is an alias for apache_request_headers().
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found