Closed qppq54s closed 7 years ago
我这儿没有问题:
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"
},
...
我这儿没有问题:
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"
},
...
估计你是想把其他的headers也返回给客户端吧?这种情况下建议最好别这么干~
那我想要把其中的一个比如“x-total-count”返回,该怎么做呢 为什么不把所有的headers返回?
目前头信息里只会解析set-cookies字段(即返回的cookie),不返回所有的headers有几方面的考虑: 1、数据就是数据,头信息就是头信息,所有的数据通过response body体传递,避免混用; 2、如果有多个并发请求的话,以哪个请求的头信息为准呢?
恩,明白了,谢谢 请问一下我怎么附加信息到返回的headers中呢,我试了conf:{headers:{}} 没有作用
在使用
this.proxy('http://jsonplaceholder.typicode.com/users?_page=1')
时,发现直接调用中返回的而 this.proxy 的返回只有这些
请问该怎么解决这个问题