apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: The response head was strangely modified after passing APISIX

Open StretchV opened this issue 5 years ago • 14 comments

Issue description

我通过修改本地的hosts对路由在postman上分别做了测试,一种是通过apisix,一种是直接访问后端的ip地址,结果是通过apisix后响应头被不知道什么原因的修改了,下面是不过apisix和过apisix的两种情况 2222222 111111

这是后端往响应头上加头信息的代码: 33333333333

没有开任何的插件,service配的也是穿透模式,不太明白为什么会这样。。

Environment

  • apisix version (cmd: apisix version):apache/apisix:2.3-alpine

StretchV avatar May 11 '21 06:05 StretchV

adding Server header to the response header is a default behavior, indicating that the request is handled by APISIX, but overriding Access-Control-Allow-Headers is a problem, what are your upstream services?

tzssangglass avatar May 11 '21 06:05 tzssangglass

upstream services is ingress-controller ,I can get the head if I bypass APISIX and visit the upstream

StretchV avatar May 11 '21 06:05 StretchV

upstream services is ingress-controller ,I can get the head if I bypass APISIX and visit the upstream

what is the value of Access-Control-Allow-Headers in the request header?

tzssangglass avatar May 11 '21 06:05 tzssangglass

这3个是用来cors跨越名访问用的, 还有我之前也有往头里加cache-control: no-cache(清除浏览器缓存)这个过完apisix后也不见了

StretchV avatar May 11 '21 07:05 StretchV

This information seems to be carried with the cors plugin enabled. You check if the cors plugin is enabled. 截屏2021-05-11 下午3 09 47

Firstsawyou avatar May 11 '21 07:05 Firstsawyou

是的 谢谢 确实有个全局插件cors! 目前我已经去掉了,而且保证了没有全局插件存在了,但是目前还是有那个响应头丢失的情况存在 1111111 222222

过apisix后cache-control: no-cache没有了..

StretchV avatar May 11 '21 07:05 StretchV

经过测试需要加上插件proxy-cache,并设置hide_cache_headers:false 才能返回给客户端,但是我不太明白为什么会这样呢,这个插件是必须要加的吗?

StretchV avatar May 11 '21 08:05 StretchV

The proxy-cache plugin is not necessary, you can provide route related configuration data, I will check it.

Firstsawyou avatar May 11 '21 08:05 Firstsawyou

{ "create_time": 1620454728, "update_time": 1620454728, "uris": [ "/bff-message-center", "/bff-message-center/*" ], "name": "gateway-test_XXXXXX___bff-message-XXXXXX", "methods": [ "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH" ], "hosts": [ "gateway-test.XXXXXX" ], "service_id": "347097464416764780", "enable_websocket": true, "status": 1 } 这是这个路由配置, service上只开了prometheus插件

StretchV avatar May 11 '21 08:05 StretchV

@StretchV the issue is fixed by https://github.com/apache/apisix/pull/3789 in v2.5?

spacewander avatar May 11 '21 09:05 spacewander

I confirmed that it has been resolved in APISIX 2.5

Firstsawyou avatar May 11 '21 09:05 Firstsawyou

那我可以先用proxy-cache这个插件配置hide_cache_headers:false 这种方式解决吗,会有什么影响吗,我目前吧这个插件配成全局插件了,我的是2.3版本

StretchV avatar May 11 '21 09:05 StretchV

那我可以先用proxy-cache这个插件配置hide_cache_headers:false 这种方式解决吗,会有什么影响吗,我目前吧这个插件配成全局插件了,我的是2.3版本

This solution looks good to me. If possible, please upgrade to 2.5.

spacewander avatar May 11 '21 09:05 spacewander

Consider solved by #3789

spacewander avatar May 11 '21 09:05 spacewander