0

My response headers look like this

HTTP/1.1 200 OK
Server: nginx/1.9.7
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-On-Trial: 1
Cache-Control: no-cache
Access-Control-Allow-Origin: http://localhost:4200
Vary: Origin
Date: Sun, 29 May 2016 00:37:31 GMT

But when I do a console.log(headers) in the RESTAdapter handleResponse function, all that is included is

EmptyObject {Content-Type: "application/json", Cache-Control: "no-cache"}

How can I access the X-On-Trail header or any other custom headers I may need?

I'm not sure if this matters but I am using ember-simple-auth. Does that strip out headers?

Vlad
  • 978
  • 6
  • 13

1 Answers1

1

I check sources. .handleResponse is called from .ajax

  ajax(url, type, options) {
    var adapter = this;

    var requestData = {
      url:    url,
      method: type
    };

    return new Ember.RSVP.Promise(function(resolve, reject) {
      var hash = adapter.ajaxOptions(url, type, options);

      hash.success = function(payload, textStatus, jqXHR) {

        let response = adapter.handleResponse(
          jqXHR.status,
          parseResponseHeaders(jqXHR.getAllResponseHeaders()), // try to check both in debugger
          payload,
          requestData
        );

So just try to stop at parseResponseHeaders(jqXHR.getAllResponseHeaders()) line and check jqXHR.getAllResponseHeaders(). If it's ok - check parseResponseHeaders()

I'll be glad to help with debug, if you have public link for your project or if you can give link for any public project with REstAdapter

About striping - it skips headers which doesn't contains colons

P.S> Thx to @Vlad xmlHttp.getResponseHeader + Not working for CORS

"Access-Control-Expose-Headers"

Used in response to a preflight request to indicate which HTTP headers can be > used when making the actual request.

Access-Control-Allow-Headers: <field-name>[, <field-name>]*

Community
  • 1
  • 1
Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44
  • Thanks for the detailed explanation. What do you mean by " it skips headers which doesn't contains colons"? Are the headers supposed to be formatted a certain way? – Vlad May 29 '16 at 19:42
  • It skip headers which has no ':' ( that's not about your case, just for information ) – Vasiliy vvscode Vanchuk May 29 '16 at 19:45
  • I did a `console.log(jqXHR.getAllResponseHeaders())` in rest.js and it still only has the two headers. Any other ideas? – Vlad May 29 '16 at 20:07
  • I figured it out with your help. The pointing me to the rest file and looking the jqXHR made me realize it wasn't an ember issue. I had to add the `"Access-Control-Expose-Headers"` header on my response with a list of headers to allow the client to view. Please add that part to your asnwer and I'll approve it. Thank you! See this answer. http://stackoverflow.com/questions/14686769/xmlhttp-getresponseheader-not-working-for-cors – Vlad May 29 '16 at 20:19