You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "zxyao145 (via GitHub)" <gi...@apache.org> on 2024/01/09 12:39:22 UTC

[I] request help: Request header modification sometimes does not take effect [apisix-go-plugin-runner]

zxyao145 opened a new issue, #155:
URL: https://github.com/apache/apisix-go-plugin-runner/issues/155

   ### Issue description
   The client uses `Content-Type:application/x-www-form-urlencoded ` to access the HTTP API. After decrypting the body to json, I reset the request header by `r.Header().Set("Content-Type", "application/json;charset=UTF-8")`, but found that it sometimes does not work.
   
   I have attempted to request 100 times, but there are 9 cases where it does not take effect
   
   the code of plugin:
   ```go
   r.Header().Set("Content-Type", "application/json;charset=UTF-8")
   r.SetBody(origBodyByte)
   
   // pluginLogger is a wrapper for log that can output traceId
   pluginLogger.Infof("request get Content-Type: %s", r.Header().Get("Content-Type"))
   ```
   the log of the plugin:
   
   ```
   2024/01/09 20:15:00 [warn] 302#302: *913 [lua] init.lua:961: 2024-01-09T20:15:00.941+0800       INFO    pluginlogger/logger.go:34       
    [00-3334f5bcb64c9c9cdf0da1997a9a81b6-5ff503ca821603ae-01] request get Content-Type: application/json;charset=UTF-8
   ```
   the log of http api:
   
   ```
   2024-01-09 20:15:00.946 [3334f5bcb64c9c9cdf0da1997a9a81b6]  [ http-nio-5001-exec-7:17758181 ] - [ DEBUG ]- [ org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor ]  Read "application/x-www-form-urlencoded;charset=UTF-8" to ["**********"]
   
   2024-01-09 20:15:00.946 [3334f5bcb64c9c9cdf0da1997a9a81b6]  [ http-nio-5001-exec-7:17758181 ] - [ DEBUG ]- [ com.xxxx.controller.TestController ]  Content-Type:application/x-www-form-urlencoded
   ```
   
   Is there anyone who can help explain the reason?
   
   
   ### Environment
   
   * APISIX Go Plugin Runner's version:
     github.com/apache/apisix-go-plugin-runner v0.5.1-0.20231128010119-a265bcd63ca1
   * APISIX version: 3.6.0
   * Go version: 1.19
   * OS (cmd: uname -a): debian:bullseye-slim
   


-- 
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: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] request help: Request header modification sometimes does not take effect in ext-plugin-pre-req [apisix-go-plugin-runner]

Posted by "Eslam3bdel3al (via GitHub)" <gi...@apache.org>.
Eslam3bdel3al commented on issue #155:
URL: https://github.com/apache/apisix-go-plugin-runner/issues/155#issuecomment-2223354813

   We had same issue with the **'content-length'** ,but get fixed by deleting it so it can be calculated again to the new length.
   
   ```
   r.SetBody(newbody)
   r.Header().Del("content-length")
   ```


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org