Luc Vanwaelscappel Luc Vanwaelscappel - 6 months ago 32
React JSX Question

How to get Header Location value from a Fetch request in ReactJS

From a ReactJS - Redux front app, I try to get the Location Header value of an REST API response.

When I Curl this :

curl -i -X POST -H "Authorization: Bearer MYTOKEN"

I Have this answer :

Server: nginx
Date: Fri, 12 Aug 2016 15:55:47 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive

When I make a Fetch in ReactJS

var url = ''
fetch(url, {
method: 'post',
credentials: 'omit',
headers: {
'Authorization': `Bearer ${token}`

I don't have any Headers in the response object :
No header in Fetch request

I tried all the response.headers functions I've found in :


But well, as headers is empty, I have empty results.

Do you know why I can't get a proper Header object filled with the headers values ?

Thanks in advance,


Thanks to John, I've found the answer.

I just had to put

Access-Control-Expose-Headers: Location

To my response headers and it worked, so now I can access Location value with :


Thx John !