maplezhang97 commented on issue #10787:
URL: https://github.com/apache/apisix/issues/10787#issuecomment-1884085483

   > hello, can u provide some steps to reproduce this issue, like a route
   
   1. I first configure the upstream service on apisix dashboard, service name 
and ip and port, and choose protocol is 'gRPC', other config almost is default 
value.
   ```
   {
     "nodes": [
       {
         "host": "127.0.0.1",
         "port": 17123,
         "weight": 1
       }
     ],
     "timeout": {
       "connect": 6,
       "send": 6,
       "read": 6
     },
     "type": "roundrobin",
     "scheme": "grpc",
     "pass_host": "pass",
     "name": "test-service",
     "desc": "test",
     "keepalive_pool": {
       "idle_timeout": 60,
       "requests": 1000,
       "size": 320
     }
   }
   ```
   2. I upload my proto.
   ```
   `syntax = "proto3";
   package pb;
   
   service TestService{
       rpc Test(TestRequest) returns TestResponse);
   }
   
   message TestRequest{
       string device_id = 1;
       string uid = 2;
   }
   
   message TestResponse{
       bool is_ok = 1;
   }
   ```
   
   3. I implemented a plugin that just prints logs for test if 
ext-plugin-post-resp can use with grpc-transcode
   ```
   func init() {
        err := plugin.RegisterPlugin(&GetRealResponse{})
        if err != nil {
                log.Fatalf("failed to register plugin response_log: %s", err)
        }
   }
   
   type GetRealResponse struct {
        plugin.DefaultPlugin
   }
   
   func (p *GetRealResponse) Name() string {
        return "response_log"
   }
   
   func (p *GetRealResponse) ParseConf(in []byte) (interface{}, error) {
        return nil, nil
   }
   
   func (p *GetRealResponse) ResponseFilter(conf interface{}, w 
pkgHTTP.Response) {
        log.Infof("enter response_log plugin")
   }
   ```
   4. I configure the route
   ```
   {
     "uri": "/test_grpc",
     "name": "test plugin",
     "priority": 1,
     "plugins": {
       "ext-plugin-post-resp": {
         "conf": [
           {
             "name": "response_log",
             "value": ""
           }
         ]
       },
       "grpc-transcode": {
         "method": "Test",
         "proto_id": "1",
         "service": "pb.TestService"
       }
     },
     "upstream_id": "494354079535858470",
     "status": 1
   }
   ```
   
   then I use postman to test http request to this gRPC service
   
![image](https://github.com/apache/apisix/assets/156065477/af5feb61-92a1-456b-adcb-b26dd116480f)
   the plugins log is 
   
![image](https://github.com/apache/apisix/assets/156065477/1c1d6031-6ed6-4315-a7fa-b700edf0bdee)
   
   I use another way to solve this problem, but i dont know why it work.
   I change my plugins code in step 3
   ```
   func (p *GetRealResponse) ResponseFilter(conf interface{}, w 
pkgHTTP.Response) {
        w.WriteHeader(200)
        originBody, err := w.ReadBody()
        if err != nil {
                log.Errorf("failed to read: %s", err)
                return
        }
        _, err = w.Write(originBody)
        if err != nil {
                log.Errorf("failed to write: %s", err)
                return
        }
   }
   ```
   
![image](https://github.com/apache/apisix/assets/156065477/f731c302-cba8-4153-8261-62fd89f7efb3)
   


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