Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.proxy 丢失headers内容 #26

Closed
qppq54s opened this issue Feb 18, 2017 · 6 comments
Closed

this.proxy 丢失headers内容 #26

qppq54s opened this issue Feb 18, 2017 · 6 comments

Comments

@qppq54s
Copy link

qppq54s commented Feb 18, 2017

在使用 this.proxy('http://jsonplaceholder.typicode.com/users?_page=1') 时,发现直接调用中返回的

headers: {
Access-Control-Allow-Credentials:true
Access-Control-Expose-Headers:X-Total-Count, Link
Cache-Control:public, max-age=14400
CF-Cache-Status:REVALIDATED
CF-RAY:33305cd0d6872246-LAX
Connection:keep-alive
Date:Sat, 18 Feb 2017 09:13:21 GMT
Etag:W/"160d-MxiAGkI3ZBrjm0xiEDfwqw"
Expires:Sat, 18 Feb 2017 13:13:21 GMT
Link:
Pragma:no-cache
Server:cloudflare-nginx
Vary:Accept-Encoding
Via:1.1 vegur
X-Content-Type-Options:nosniff
X-Powered-By:Express
X-Total-Count:10
}

而 this.proxy 的返回只有这些

headers: {
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=utf-8
Date:Sat, 18 Feb 2017 09:05:13 GMT
set-cookie:__cfduid=d8215742543560aabf718ebc4a66c415f1487408713; expires=Sun, 18-Feb-18 09:05:13 GMT; path=/; domain=.typicode.com; HttpOnly
Transfer-Encoding:chunked
Vary:Accept-Encoding
}

请问该怎么解决这个问题

@xiongwilee
Copy link
Owner

我这儿没有问题:

exports.test = function*(){
	this.body = yield this.proxy({test:'http://jsonplaceholder.typicode.com/users?_page=1'})
}

返回:

{
...
"headers": {
"date": "Sat, 18 Feb 2017 12:08:39 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"set-cookie": [
"__cfduid=dbcee87783db1b6e65be02b998ab2d43f1487419719; expires=Sun, 18-Feb-18 12:08:39 GMT; path=/; domain=.typicode.com; HttpOnly"
],
"x-powered-by": "Express",
"vary": "Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "public, max-age=14400",
"pragma": "no-cache",
"expires": "Sat, 18 Feb 2017 16:08:39 GMT",
"x-total-count": "10",
"access-control-expose-headers": "X-Total-Count, Link",
"link": "",
"x-content-type-options": "nosniff",
"etag": "W/\"160d-MxiAGkI3ZBrjm0xiEDfwqw\"",
"content-encoding": "gzip",
"via": "1.1 vegur",
"cf-cache-status": "EXPIRED",
"server": "cloudflare-nginx",
"cf-ray": "33315d9c91166d00-SJC"
},
...

1 similar comment
@xiongwilee
Copy link
Owner

我这儿没有问题:

exports.test = function*(){
	this.body = yield this.proxy({test:'http://jsonplaceholder.typicode.com/users?_page=1'})
}

返回:

{
...
"headers": {
"date": "Sat, 18 Feb 2017 12:08:39 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"set-cookie": [
"__cfduid=dbcee87783db1b6e65be02b998ab2d43f1487419719; expires=Sun, 18-Feb-18 12:08:39 GMT; path=/; domain=.typicode.com; HttpOnly"
],
"x-powered-by": "Express",
"vary": "Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "public, max-age=14400",
"pragma": "no-cache",
"expires": "Sat, 18 Feb 2017 16:08:39 GMT",
"x-total-count": "10",
"access-control-expose-headers": "X-Total-Count, Link",
"link": "",
"x-content-type-options": "nosniff",
"etag": "W/\"160d-MxiAGkI3ZBrjm0xiEDfwqw\"",
"content-encoding": "gzip",
"via": "1.1 vegur",
"cf-cache-status": "EXPIRED",
"server": "cloudflare-nginx",
"cf-ray": "33315d9c91166d00-SJC"
},
...

@xiongwilee
Copy link
Owner

估计你是想把其他的headers也返回给客户端吧?这种情况下建议最好别这么干~

@qppq54s
Copy link
Author

qppq54s commented Feb 19, 2017

那我想要把其中的一个比如“x-total-count”返回,该怎么做呢
为什么不把所有的headers返回?

@xiongwilee
Copy link
Owner

目前头信息里只会解析set-cookies字段(即返回的cookie),不返回所有的headers有几方面的考虑:
1、数据就是数据,头信息就是头信息,所有的数据通过response body体传递,避免混用;
2、如果有多个并发请求的话,以哪个请求的头信息为准呢?

@qppq54s
Copy link
Author

qppq54s commented Feb 19, 2017

恩,明白了,谢谢
请问一下我怎么附加信息到返回的headers中呢,我试了conf:{headers:{}} 没有作用

@qppq54s qppq54s closed this as completed Feb 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants