apache / apisix-java-plugin-runner

APISIX Plugin Runner in Java
https://apisix.apache.org/
Apache License 2.0
128 stars 95 forks source link

request help: Client send Accept header value is overriden when set accept value in filter method #251

Open yujinchoi-94 opened 1 year ago

yujinchoi-94 commented 1 year ago

Issue description

I'm accessing the Accept header value in filter and postFilter method.

Here's what I've experienced.

  1. the client sends accept value as (blank)
  2. In the filter method, set accept value, for example application/xml;charset=euc-kr, to call an upstream server with that accept header value.
  3. In the post filter method, access accept header value. and It turns out application/xml;charset=euc-kr not a (blank)

It only happens when the client send accept header is

Here's my code

   @Override
    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
        var config = getConfig(request.getConfig(this), ContentTypeConverterFilterConfig.class);

        request.setHeader(HTTP_HEADER_ACCEPT, config.getUpstreamAccept()); // config.getUpstreamAccept() is `application/xml;charset=euc-kr`
        request.setHeader(HTTP_OPENAPI_ORIGINAL_HEADER_ACCEPT,
            getNonBlankHeaderValue(request.getVars(NginxVars.HTTP_ACCEPT.getValue()))); // I have to add another header value so that I can client send accept header value in postFilter method

        chain.filter(request, response);
    }

    @Override
    public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
    ...
    request.getVars(NginxVars.HTTP_ACCEPT.getValue()) // not a client send accept header value (`  `)
    ...
}

public enum NginxVars {
    HTTP_ACCEPT("http_accept"),
    REQUEST_URI("request_uri");
   ...

Environment

0.4.0