Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Question: How can I access response headers? #103

Closed
ChavaSobreyra opened this issue May 2, 2016 · 3 comments
Closed

Question: How can I access response headers? #103

ChavaSobreyra opened this issue May 2, 2016 · 3 comments

Comments

@ChavaSobreyra
Copy link

Our backend passes certain information through response headers that we need to be able to see/use on our ember application.

I see support for raw requests were removed, and I don't see anywhere that the full jqXHR is exposed.

Was there a philosophical reasoning behind this? Is there a workaround?

@alexlafroscia
Copy link
Collaborator

You can still do raw! The code is right here:

raw(url, options) {
const hash = this.options(url, options);
const requestData = {
type: hash.type,
url: hash.url
};
if (isJSONAPIContentType(hash.headers['Content-Type']) && requestData.type !== 'GET') {
if (typeof hash.data === 'object') {
hash.data = JSON.stringify(hash.data);
}
}
return new Promise((resolve, reject) => {
hash.success = (payload, textStatus, jqXHR) => {
let response = this.handleResponse(
jqXHR.status,
parseResponseHeaders(jqXHR.getAllResponseHeaders()),
payload,
requestData
);
this.pendingRequestCount--;
if (isAjaxError(response)) {
run.join(null, reject, { payload, textStatus, jqXHR, response });
} else {
run.join(null, resolve, { payload, textStatus, jqXHR, response });
}
};

You should get back the raw XHR object to access the headers that way.

@ChavaSobreyra
Copy link
Author

ChavaSobreyra commented May 3, 2016

Thank you! I'm on 0.7.1 getting the raw deprecation warnings, and didn't see much mention on the new readme docs.

@alexlafroscia
Copy link
Collaborator

Oh, okay! raw isn't going away any time soon, so that's the way to go.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants