vector4wang opened a new issue, #10471:
URL: https://github.com/apache/apisix/issues/10471

   ### Description
   
   I have written a custom plugin in Java with the aim of adding plugin 
parameters to the HTTP response header. The code is as follows
   ```java
   @Component
   public class CustomFilter implements PluginFilter {
   
       private final Logger logger = 
LoggerFactory.getLogger(CustomFilter.class);
   
       @Override
       public String name() {
           return "CustomFilter";
       }
   
       @Override
       public void filter(HttpRequest request, HttpResponse response, 
PluginFilterChain chain) {
   
           // parse `conf` to json
           String configStr = request.getConfig(this);
           logger.info("filter configStr: {}", configStr);
           JSONObject conf = JSONUtil.parseObj(configStr);
           conf.forEach((k, v) -> {
               response.setHeader(k, (String) v);
           });
   
           chain.filter(request, response);
       }
   
       @Override
       public void postFilter(PostRequest request, PostResponse response, 
PluginFilterChain chain) {
           logger.info("响应后处理");
           chain.postFilter(request, response);
       }
   
       @Override
       public Boolean requiredRespBody() {
           return PluginFilter.super.requiredRespBody();
       }
   }
   ```
   
   I created a plugin enabled route using the admin API,
   ```curl
   curl --location --request PUT 
'xxxxxxx:9180/apisix/admin/routes/486660216419517121' --header 'X-API-KEY: 
xxxxxxxxxxxxxxxxxx' --header 'Content-Type: application/json' --data '{
       "name": "extHello",
       "uri": "/extHello",
       "plugins": {
           "ext-plugin-pre-req": {
               "conf": [
                   {
                       "name": "CustomFilter",
                       "value": "{}"
                   }
               ]
           }
       },
       "upstream": {
           "nodes": {
               "xxxxxx:8080": 1
           },
           "type": "roundrobin"
       }
   }'
   ```
   
   If conf.value is {}, the gateway can forward normally and the client can 
receive the response body normally. At this time, there is no additional key in 
the response header
   
   **But** if conf.value is like this
   ```json
   "conf": [
         {
             "name": "CustomFilter",
             "value": "{\"X-CUSTOMER-KEY\":\"123\"}"
         }
     ]
   ```
   The client cannot receive the response body, but the response header has a 
new key 'X-CUSTOMER-KEY' added
   
![Snipaste_2023-11-10_17-08-38](https://github.com/apache/apisix/assets/9328963/e5768923-f65f-4f5c-b391-2757cf29d92f)
   
![Snipaste_2023-11-10_17-08-49](https://github.com/apache/apisix/assets/9328963/66c2ca47-2005-4e09-9787-cda9437bab46)
   
   I compared the logs of Apisix and output an extra line without a response 
body
   
   **`use 200 as the default HTTP Status Code when setStatusCode is not 
called`**
   
   I know there is a problem here, but I don't know how to solve it
   
   Does anyone know what the reason is?
   
   
   
   
   
   ### Environment
   
   - APISIX version (run `apisix version`): 3.5.0
   - Operating system (run `uname -a`): docker apache/apisix:3.5.0-debian
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`): 3.4.15
   - Plugin runner version, for issues related to plugin runners: 
   ```xml
           <dependency>
               <groupId>org.apache.apisix</groupId>
               <artifactId>apisix-runner-starter</artifactId>
               <version>0.4.0</version>
           </dependency>
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to