diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index b88ade7..b7400b0 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -15,6 +15,7 @@ package plugin import ( + "context" "net/http" hrc "github.com/api7/ext-plugin-proto/go/A6/HTTPReqCall" @@ -25,7 +26,7 @@ import ( pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http" ) -func handle(conf RuleConf, w http.ResponseWriter, r pkgHTTP.Request) error { +func handle(conf RuleConf, ctx context.Context, w http.ResponseWriter, r pkgHTTP.Request) error { return nil } @@ -36,6 +37,10 @@ func reportAction(id uint32, req *inHTTP.Request, resp *inHTTP.Response) *flatbu return builder } + if req != nil && req.FetchChanges(id, builder) { + return builder + } + hrc.RespStart(builder) hrc.RespAddId(builder, id) res := hrc.RespEnd(builder) @@ -55,7 +60,9 @@ func HTTPReqCall(buf []byte) (*flatbuffers.Builder, error) { if err != nil { return nil, err } - err = handle(conf, resp, req) + + ctx := context.Background() + err = handle(conf, ctx, resp, req) if err != nil { return nil, err } diff --git a/pkg/http/http.go b/pkg/http/http.go index cfc4284..d7ca549 100644 --- a/pkg/http/http.go +++ b/pkg/http/http.go @@ -32,6 +32,11 @@ import ( type Request interface { // ID returns the request id ID() uint32 + // ConfToken returns the token represents the configuration of current route. + // Each route have its unique token, so we can use it to distinguish different + // route in the same plugin. + ConfToken() uint32 + // SrcIP returns the client's IP SrcIP() net.IP // Method returns the HTTP method (GET, POST, PUT, etc.)