Can't get location from response header
See original GitHub issueHi,
I’m trying to get the properties location
from the response, but superagent doesn’t seem to see it, in spite of the properties being set and visible from the network console.
Is it because the reponse body is empty ?
Thanks for your help 😃 Bob
# Extract from my code
.end(function(error, response){
console.log('response', error, response.headers);
[...]
})
# Extract from Response Headers from network console :
Date:Thu, 15 Oct 2015 12:59:30 GMT
Expires:0
Location:/tmp/project-pic-4730126112057571929.jpg
Pragma:no-cache
Server:nginx/1.6.2
# console.log(response.headers)
Object {
pragma: "no-cache",
cache-control: "no-cache, no-store, max-age=0, must-revalidate",
expires: "0",
content-type: null
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Can't get location from response header · Issue #770 - GitHub
Hi, I'm trying to get the properties location from the response, but superagent doesn't seem to see it, in spite of the properties...
Read more >Can't accses fetch() response location header in JS
I can see the header and the desired token via Chrome dev tools, but I can't get and use it on my JS...
Read more >Location - HTTP - MDN Web Docs - Mozilla
The Location response header indicates the URL to redirect a page to. It only provides a meaning when served with a 3xx (redirection)...
Read more >How to get the Location response header : r/shortcuts - Reddit
I'm using "Get contents of url" to make a POST request and the response has a Location header that I need. I've tried...
Read more >HTTP headers | Location - GeeksforGeeks
To check this Location in action go to Inspect Element -> Network check the response header for Location like below, Location is highlighted...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Stumbled upon the same issue just now: Location header in response visible in network tab but not in the response object. I think the answer given by @roshanraj is not quite correct. The location header is indeed stripped away by the browser if this is a CORS request and the CORS headers of the response do not allow the location header to be exposed. The CORS header in question is
Access-Control-Expose-Headers
. If the response hasAccess-Control-Expose-Headers:Location
, then the browser exposes the Location header just fine and superagent yields its value happily.So, if you have control over the server side, you just need to set this header. If you are for example using express with the cors middleware you could do something like:
Hope this helps the next person which googles for “superagent response location header” 😉
See also: http://www.w3.org/TR/cors/#access-control-expose-headers-response-header
Oh thats cool. Thank you for correcting me.