# 5. CORS 進階之 Expose-Headers
#### 1. getAllResponseHeaders
這一篇來講講如何獲得從跨域的服務器端返回的響應頭部信息。先用一段js獲取響應的頭部信息:
```
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
console.log(xhttp.getAllResponseHeaders());
}
};
xhttp.open("GET", "http://localhost:8080", true);
xhttp.send();
```
效果圖如下:

內容是下面這樣的:
```
Last-Modified: Fri, 15 Jan 2016 06:03:50 GMT
Content-Type: text/html
```
這樣是OK的,然而有時候會在服務器端自己添加響應的頭部信息,比如:
```
add_header 'X-Powered-By' 'rails365';
```
那又能否獲得到呢,來試一下:

沒有生效,也沒有報錯。
#### 2. Access-Control-Expose-Headers
然而,我們需要服務器端處理一下,把`X-Powered-By`這個頭部能夠讓客戶端的js讀取到。
這就是`Access-Control-Expose-Headers`這個指令所發揮的作用。
```
add_header 'X-Powered-By' 'rails365';
add_header 'Access-Control-Expose-Headers' 'X-Powered-By';
```
重新發送跨域請求:

可見,成功輸出了響應的頭部信息`X-Powered-By`的內容了。
完結。