question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get location from response header

See original GitHub issue

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 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:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
basti1302commented, Nov 10, 2015

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 has Access-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:

app.use(cors({                                                                 
  exposedHeaders:['Location'],                                                                                                                         
}));

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

0reactions
roshanrajcommented, Nov 14, 2015

Oh thats cool. Thank you for correcting me.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found