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.

Custom headers not working

See original GitHub issue

I’m trying to get custom headers to work. The example in the documentation doesn’t seem to work. And returns a not found on the method.

this.imageLoaderConfig.setHttpRequestOptions({
  headers: {
    Authorization: 'Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=='
  }
});

In the code I’m seeing setHttpHeaders is available and that expecting an HttpHeader object.
Tried the example below but not seeing a header.

import { HttpHeaders } from '@angular/common/http';

let headers = new HttpHeaders();
    headers.append('Authorization', 'Bearer blablah-blah');
    imageLoaderConfig.setHttpHeaders(headers);
    imageLoaderConfig.enableDebugMode();

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
markrinkelcommented, May 7, 2019

Yes, that works!

Thank you.

0reactions
nylzcommented, May 24, 2019

constructor of app.component.ts:

constructor(
    imageLoaderConfig: ImageLoaderConfigService,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private pushyInitializer: PushyInitializerService,
    private platform: Platform,
    private router: Router,
    private httpClient: HttpClient,
    private domSanitizer: DomSanitizer
  ) {
    imageLoaderConfig.setConcurrency(10);
    imageLoaderConfig.useImageTag(true);
    imageLoaderConfig.enableSpinner(true);
    imageLoaderConfig.setSpinnerName('crescent');
    imageLoaderConfig.setSpinnerColor('primary');
    imageLoaderConfig.setFallbackUrl('assets/images/image_placeholder.png');
    imageLoaderConfig.enableFallbackAsPlaceholder(false);
    const headers = new HttpHeaders().set('Authorization', 'Bearer blablabla')
                .set('DeviceToken', 'blablabla');
    imageLoaderConfig.setHttpHeaders(headers);
    imageLoaderConfig.enableDebugMode();

  }

and in the template of the component / page:

<img-loader [src]="getImageUrl(object)" (click)="show_detail(object, i)"></img-loader>

then the request header to http://localhost:8080/Application_www/images/web/boxthumb/2039 looks like:

Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: */*
Accept-Language: de-DE,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localhost:8100/main/overview
Cookie: JSESSIONID=C64540999B1BF4A7364A6EC555BA89B3
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom headers not applied · Issue #1317 - GitHub
Manually set custom headers in aws console: security related headers (e.g., X-Frame-Options) are set, but cache-control is not set. cache- ...
Read more >
Unable to define custom headers using HttpHeaders on ...
Try checking for any HttpInterceptors that are running on requests. Its possible your headers are being overwritten.
Read more >
Custom headers - AWS Amplify Hosting
Custom HTTP headers enable you to specify headers for every HTTP response. Response headers can be used for debugging, security, and informational purposes....
Read more >
Access-Control-Allow-Headers - HTTP - MDN Web Docs
It indicates that a custom header named X-Custom-Header is supported by CORS requests to the server (in addition to the CORS-safelisted ...
Read more >
Custom headers in netlify.toml not working - Support
Hi, I'm having trouble getting custom headers working, I'm setting them in the netlify.toml file, but no matter what I try they don't...
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