提交 2c61395e 编写于 作者: J Joshua Peek

Add X-Request-URL

上级 304f4054
......@@ -162,6 +162,23 @@ fetch('/users')
})
```
### Response URL caveat
The `Response` object has a URL attribute for the final responded resource.
Usually this is the same as the `Request` url, but in the case of a redirect,
its all transparent. Newer versions of XHR include a `responseURL` attribute
that returns this value. But not every browser supports this. The compromise
requires setting a special server side header to tell the browser what URL it
just requested (yeah, I know browsers).
``` ruby
response.headers['X-Request-URL'] = request.url
```
If you want `response.url` to be reliable, you'll want to set this header. The
day that you ditch this polyfill and use native fetch only, you can remove the
header hack.
## Browser Support
![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png)
......
......@@ -181,7 +181,7 @@
status: status,
statusText: xhr.statusText,
headers: headers(xhr),
url: xhr.responseURL
url: xhr.responseURL || xhr.getResponseHeader('X-Request-URL')
}
resolve(new Response(xhr.responseText, options))
}
......
......@@ -20,8 +20,11 @@ var routes = {
}));
})
},
'/hello': function(res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
'/hello': function(res, req) {
res.writeHead(200, {
'Content-Type': 'text/plain',
'X-Request-URL': 'http://' + req.headers.host + req.url
});
res.end('hi');
},
'/redirect/301': function(res) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册