Skip to content

Commit

Permalink
feat: expose ConfToken method
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander committed May 28, 2021
1 parent 05f4082 commit 4ad02de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package plugin

import (
"context"
"net/http"

hrc "github.com/api7/ext-plugin-proto/go/A6/HTTPReqCall"
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down

0 comments on commit 4ad02de

Please sign in to comment.