3

I have an Django backend. And trying to get http headers from it by using: 1) Angular 4.3 Http (it is going to be deprecated) 2) Plain XmlHttprequest. 3) Angular 4.3 HttpClient

1) and 2) have headers. But 3) does not.


Headers from 1):

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    console.log(this);
    console.log(xhttp.getAllResponseHeaders());
  }
};
xhttp.open("GET", "http://127.0.0.1:8000/csbg/survey/sometest/", true);
xhttp.send();

Headers from 2):

import { HttpModule} from '@angular/http';

     this.http.get('http://127.0.0.1:8000/csbg/survey/sometest/')
     .subscribe(
       data=>{
         console.log('GET OK')
         console.log(data)
       },
       error=>{
         console.log("GET ERROR: " + error);
       }
     )

Headers from (2)


Headers from 3):

import { HttpClient} from '@angular/common/http'

  this.http.get('http://127.0.0.1:8000/csbg/survey/sometest/', { observe: 'response' })
  .subscribe(
    data=>{
      console.log('GET OK')
      console.log(data)
    },
    error=>{
      console.log("GET ERROR: " + error);
    }
  )

There is no headers ! Why?

Also, Why default Access-Control-Expose-Headers headers is not present in there:

By default, only the 6 simple response headers are exposed:

Cache-Control Content-Language Content-Type Expires Last-Modified Pragma

but my custom header is ?

5
  • The docs show accessing an arbitrary header: angular.io/guide/http#reading-the-full-response. What happens if you explicitly try to get the one you’re looking for? Commented Sep 24, 2017 at 11:22
  • Thanks for you help. When I explicitly query for an header: var hdr = data.headers.get('asdf') all headers are appeared in console.log(data) The problem is solved. Thank you. It is a little strange though :) Commented Sep 24, 2017 at 12:03
  • And toward a default Access-Control-Expose-Headers header. As I understood, it only allows to send headers. But do nothing to set them. Commented Sep 24, 2017 at 12:10
  • I assume the headers are only parsed lazily then, as you request them, to make all the times you don’t need to access any more efficient. Commented Sep 24, 2017 at 12:11
  • @AndriyKutsevol Is there already a solution to get for example content-disposition? because I am trying that right now but I always get null. Commented Nov 7, 2017 at 15:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.