Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHttp response do not include headers #5237
Comments
|
Hey guys, i have found where the problem is and changed to get what i need. In Http.dev.js on line 10645 aprox. i have added this basic snipet:
sorry i did not do it in typescript because i was lazy to recompile. also, of course, had to add the headers to the dependencies array and required it. I hope it helps. EDIT In xhr_backend.ts, XHRConnection class line 18. Thanks |
|
Hi all, I'm having this same issue in alpha.44. I can't access the response header information that are supposed to be present in the headers map of the response. Example: var req = new Request({
url: `localhost/api/products`,
method: RequestMethods.Get
});
this.http.request(req).subscribe(
res => {
// Can't access the headers of the response here.... res.headers is empty
},
error => { ... },
_ => {}
);If I check the network traffic in the browser's dev tools, the response headers are present... |
|
See my edit. I have a workaround to this issue untill they fix it. Hope it helps you |
|
Hi @bruno-quintanilha, thanks for your suggestion. After some diving into angular2 code (and yours too), I realize that not all response headers are present when I invoke _xhr.getAllResponseHeaders(). Actually, only a couple of them are present! Here follow the real response headers: And the result of the _xhr.getAllResponseHeaders(): "Content-Language: pt-PT Content-Type: application/json; charset=utf-8" Are there any suggested workaround? |
|
Hi there, try access directly to your custom header with: _xhr.getResponseHeader('x-total-count'); Maybe some checking if it exists. But i can tell you that i am able to access all response headers with the previous sugestion. Still, does this value really needs to be a header? cant you send it with the response and a custom Http class (extend it or encapsulate) to intercept the response and separate that value from the real response? Hope it helps |
|
BTW. Aqui da ilha da Madeira! @cangosta |
Closes angular#5237
Closes angular#5237
Properly parse and add response Headers to Response. Closes angular#5237
Properly parse and add response Headers to Response. Closes angular#5237
Properly parse and add response Headers to Response. Closes angular#5237
Properly parse and add response Headers to Response. Closes angular#5237
|
Hi all! My custom headers are not being retrieved, for they do not appear it the headers map... Anyone with the same problem? tbragaf |
|
I have the same problem. Tried the workaround, with no success. |
|
we're simply grabbing headers from the raw XHR object, so if they don't appear there, there's not a whole lot we can do about it, unless there's something else we're missing. for those having issues, if you do a manual XHR request (see: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest ) - are you able to access the headers you're looking for? |
|
My API was used in an NG1 app, so yes. tbragaf |
|
I am using the alpha46, and still not able to retrieve the response headers. Testing my WS with the REST Client, response headers are there. I can even see them in the browser developer's console, but not just on the my angular2 response object. |
|
Alpha46 doesnt Support headers on response, it is a bug. |
|
Ah I see. I had an issue with RxJs when upgrading to alpha48, so I have not tried it yet. As of current, I am still on alpha46 and retrieving the headers using the fetch API while waiting for the bug fix. |
|
@tbragaf http://plnkr.co/edit/FJj4Zqze6xpBCcH2M5Bl?p=preview <- this is with alpha 50, and i believe has been like this since 46 or 47. Could you look at the plunker please and see if you're doing things differently? |
|
@robwormald Make sure you test this under the limit of 24 hours :) The result should be That header is not present, but you can see it if you go to the "Network" tab. @robwormald If you confirm this, can you please re-open the issue? |
|
I can confirm they don't appear, but as I said above, its not something we have any control over. See this demo using vanilla XMLHttpRequest: http://plnkr.co/edit/u2YWls1U5Rw5eS74CQWA?p=preview That throws an error : |
|
@robwormald Thank you, |
|
|
|
yup! Thanks @tbragaf. That's the issue I was having. |
|
@tchoulihan that's not related to Angular2 http://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin |
|
Maybe it can help. My solution was to add this in the backend, the Access-Control-Expose-Headers made the trick:
Then on front end this worked fine:
|
|
The trick is to use "Access-Control-Expose-Headers" |
|
The explication about this problem is here |
|
Hi. Fixed by adding below code in webapi controller. |
|
How can i get the full response object...? this.http.get(url, options)
.toPromise()
.then(data => {
console.log(data) // getting response body but not response object with headers and body
}) |
|
@shivarajnaidu https://angular.io/guide/http#reading-the-full-response this.http.xxx(url, { observe: 'response' }) |
|
How Can I read Response Header (Content-Disposition)? When I check at either Postman or Google Chrome Network tab, I can see 'Content-Disposition' at the response headers section, but NOT able to read at Angular Code.
|
|
@bhupal4all https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers, not related to Angular. |
|
Thanks @trotyl , I set 'Access-Control-Expose-Headers' at Node Js Server and am able to read 'Content-Disposition' at Angular code. |
|
In case there still is someone having trouble with this, I'll leave my solution for both the backend and frontend. Heres how you set the headers: https://github.com/rsbrum/NodeJS-RESTAPI-JWTAuth/blob/master/jwt-auth.js Heres how you access the header on the client side: https://github.com/rsbrum/Angular6-JWT-Auth/blob/master/src/app/shared/interceptor/interceptor.service.ts |
|
i'm getting error while send x-auth-token in header.
|
|
I have the same problem. I'm invoking an Identity Server service and i hope that it return Authorization header. This header is coming ok but from JavaScript when i make getAllResponseHeaders i can't get it. Then, i found this topic and reading it, i tried send Expose-Headers: req.setRequestHeader('Access-Control-Expose-Headers', 'Authorization'); But i get the same result: "pragma: no-cache It not returns authorization header. Can you helpme with another idea? Thanks!! |
|
@santiagomolinadecastro |
|
Thanks for your help @trotyl |
|
The question is. Why i can see the header in my browser (in network section) and i can't see this header in my JavaScript code? The service returns that header but from JavaScript i can't get it. The question is, Why? |
|
@santiagomolinadecastro Because Web is designed to be secure, same reason for why I cannot get HTTP-only cookie in JavaScript. |
|
@trotyl thanks!!! |
|
In my case in the
And at my Angular Side In the Component.
At my Service Side.
|
it's working, god after 2 fucking days, just for the fucking header |
|
@meitix @pkozlowski-opensource correct brother this is API problem. |
|
I have got a fix, |
|
meitix |
|
API (Node Js): Ex: You can replace name-of-expose-header by etag. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |

Maybe i am doing something wrong but when i make a request with Http i can see on the Network tab on chrome that the response include a custom header called 'Authorization' used to refresh the JWT. But when i try to access the response.headers it prints empty on the console.
the same behaviour when printing keys().
the request headers, on the other hand, do print all the custom headers i add to the request.