javascriptdojojsonreststoredojo.xhrget

How to get the response headers in dojo/store/JsonRest?


I’m using dojo/store/JsonRest to fetch for some data. But I also need the response headers. How can I access them?

this.transport = new JsonRest({
  target: "my/target"
});

this.transport.query({}).then(function(resp) {
  debugger; // <- I want to get the response headers here!
})

I tried accessing it by using the this keyword within the function at debugger time. But that is just the window object.

Is that even possible?


Solution

  • dojo/store/JsonRest by itself do not provide a way to get the headers, but here is an example of how you can get all or individual headers.

    var transport = new JsonRest({
      target: "my/target"
    });
    
    var result = transport.query({});
    
    result.then(function(resp) {
      var localXHR = result.ioArgs.xhr;
    
      // get all headers, return an String
      console.log(localXHR.getAllResponseHeaders());
    
      // get one header
      console.log(localXHR.getResponseHeader('content-type'));
    
      // do something with the response
      console.log(resp);
    });
    

    Hope it helps