SylviaBABY commented on code in PR #93:
URL: 
https://github.com/apache/apisix-go-plugin-runner/pull/93#discussion_r903336742


##########
docs/en/latest/getting-started.md:
##########
@@ -132,7 +132,42 @@ We can see that the RequestFilter takes the value of the 
body set in the configu
 (respond directly in the plugin), it will response directly in the APISIX 
without touching the upstream. We can also set response headers in the plugin 
and touch the upstream
 at the same time by set RespHeader in `pkgHTTP.Request`.
 
-For the `pkgHTTP.Request`, you can refer to the API documentation provided by 
the Go Runner SDK:
+`ResponseFilter` supports rewriting the response during the response phase, we 
can see an example of its use in the ResponseRewrite plugin:
+
+```go
+type ResponseRewriteConf struct {
+    Status  int               `json:"status"`
+    Headers map[string]string `json:"headers"`
+    Body    string            `json:"body"`
+}
+
+func (p *ResponseRewrite) ResponseFilter(conf interface{}, w pkgHTTP.Response) 
{
+       cfg := conf.(ResponseRewriteConf)
+       if cfg.Status > 0 {
+               w.WriteHeader(200)
+       }
+
+       w.Header().Set("X-Resp-A6-Runner", "Go")
+       if len(cfg.Headers) > 0 {
+               for k, v := range cfg.Headers {
+                       w.Header().Set(k, v)
+               }
+       }
+
+       if len(cfg.Body) == 0 {
+               return
+       }
+       _, err := w.Write([]byte(cfg.Body))
+       if err != nil {
+               log.Errorf("failed to write: %s", err)
+       }
+}
+```
+
+We can see that `ResponseFilter` will rewrite the status, header and response 
body of the response phase according to the configuration.
+In addition, we can also get the status and headers in the original response 
through `pkgHTTP.Response`.
+
+For the `pkgHTTP.Request` and `pkgHTTP.Response`, you can refer to the API 
documentation provided by the Go Runner SDK:
 https://pkg.go.dev/github.com/apache/apisix-go-plugin-runner

Review Comment:
   ```suggestion
   We can see that `ResponseFilter` will rewrite the status, header, and 
response body of the response phase according to the configuration.
   
   In addition, we can also get the status and headers in the original response 
through `pkgHTTP.Response`.
   
   For the `pkgHTTP.Request` and `pkgHTTP.Response`, you can refer to the [API 
documentation](https://pkg.go.dev/github.com/apache/apisix-go-plugin-runner) 
provided by the Go Runner SDK.
   ```



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