gaoxingliang commented on issue #262:
URL: 
https://github.com/apache/apisix-java-plugin-runner/issues/262#issuecomment-1730865293

   @youth-lee As a workaround you can refer to the code in: 
https://github.com/gaoxingliang/apisix-java-plugin-runner/blob/encrypt-response/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/PostRequest.java#L88
   
   I added one method to return a map of list values.
   and then in the filter: 
https://github.com/gaoxingliang/apisix-java-plugin-runner/blob/encrypt-response/runner-starter/src/main/java/org/apache/apisix/plugin/runner/EncryptResponseFilter.java#L30
   it will get the upstream response headers correctly.
   
   If you donot want to change the code, you can do the java reflect in your 
code and get the req and do the parse.
   
   The below code is an example in python to add two headers:
   ```python
   from http.server import BaseHTTPRequestHandler, HTTPServer
   
   class CustomRequestHandler(BaseHTTPRequestHandler):
       def do_GET(self):
           self.send_response(200)
           self.send_header('Content-type', 'application/json')
           self.send_header('Custom-Header', 'Custom Value')
           self.send_header('header1', 'v1')
           self.send_header('header1', 'v2')
           self.end_headers()
           
           response = '{"message": "Hello, world!"}'
           self.wfile.write(response.encode('utf-8'))
   
   def run_server():
       host = '0.0.0.0'
       port = 8100
       
       server = HTTPServer((host, port), CustomRequestHandler)
       server.serve_forever()
   
   if __name__ == '__main__':
       run_server()
   
   ```
   
   and below is the log it printed:
   ```
    2023-09-22 06:10:35,919 INFO  epollEventLoopGroup-2-2          - req 
headers: {Content-type=application/json, header1=v2, Custom-Header=Custom 
Value, Server=BaseHTTP/0.6 Python/3.6.8, Date=Fri, 22 Sep 2023 06:10:35 GMT}
    2023-09-22 06:10:35,920 INFO  epollEventLoopGroup-2-2          - req 
headers map:{Content-type=[application/json], header1=[v1, v2], 
Server=[BaseHTTP/0.6 Python/3.6.8], Custom-Header=[Custom Value], Date=[Fri, 22 
Sep 2023 06:10:35 GMT]}
   
   ```
   


-- 
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