apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.39k stars 2.91k forks source link

[BUG] I want to modify the content-type of returning data, but the modified Content-Type cannot take effect #5594

Open creabob opened 1 month ago

creabob commented 1 month ago

Is there an existing issue for this?

Current Behavior

in this case, HTTP return json data, I want to change to the return format of XML, but the Content-Type cannot be modified.

Expected Behavior

i can change the response header in exchange, exchange.getResponse().getHeaders().setContentType(xxx)

Steps To Reproduce

modify the body and header of response. return changed body but the content-type of response header un-changed

Environment

ShenYu version(s):
master

Debug logs

No response

Anything else?

image

content-type use single method to require, However, it is not obtained from exchange but from Attribute,

image

when i add this line code ,it can fix ,is it correct?

moremind commented 1 month ago

what?

creabob commented 1 month ago
image

in modifyResponse plugin, i add this conditions,

image

addKey success, but modify key failed .

creabob commented 1 month ago

当我修改返回值的header头时,content-type字段无法修改,无论是我自定义的插件还是modifyResponse插件,都不成功。 我修改的方式是加入这段代码 exchange.getResponse().getHeaders().setContentType(xxx)

当我debug时,发现content-type有单独的方法去获取,可是并不是通过exchange的值获取。 image 我想问,正确修改response的content-type方式是什么?