Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyy93 committed May 20, 2024
1 parent 7302776 commit 37dd170
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
uses: docker/build-push-action@v4
with:
push: true
tags: release.daocloud.io/skoala/envoy-extproc-payloadlimit-demo-go:${{ github.sha }}
tags: release.daocloud.io/skoala/envoy-extproc-payloadlimit-demo-go:${{ github.sha }}
79 changes: 79 additions & 0 deletions body-rewrite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
ep "github.com/wrossmorrow/envoy-extproc-sdk-go"
"log"
)

type bodyRewriteRequestProcessor struct {
opts *ep.ProcessingOptions
bodyRewrite string
}

func (s *bodyRewriteRequestProcessor) GetName() string {
return "body-rewrite"
}

func (s *bodyRewriteRequestProcessor) GetOptions() *ep.ProcessingOptions {
return s.opts
}

func (s *bodyRewriteRequestProcessor) ProcessRequestHeaders(ctx *ep.RequestContext, headers ep.AllHeaders) error {
return ctx.ContinueRequest()
}

func (s *bodyRewriteRequestProcessor) ProcessRequestBody(ctx *ep.RequestContext, body []byte) error {
ctx.ReplaceBodyChunk([]byte(s.bodyRewrite))
return ctx.ContinueRequest()
}

func (s *bodyRewriteRequestProcessor) ProcessRequestTrailers(ctx *ep.RequestContext, trailers ep.AllHeaders) error {
return ctx.ContinueRequest()
}

func (s *bodyRewriteRequestProcessor) ProcessResponseHeaders(ctx *ep.RequestContext, headers ep.AllHeaders) error {
return ctx.ContinueRequest()
}

func (s *bodyRewriteRequestProcessor) ProcessResponseBody(ctx *ep.RequestContext, body []byte) error {
return ctx.ContinueRequest()
}

func (s *bodyRewriteRequestProcessor) ProcessResponseTrailers(ctx *ep.RequestContext, trailers ep.AllHeaders) error {
return ctx.ContinueRequest()
}

const kbodyRewrite = "body-rewrite"

func (s *bodyRewriteRequestProcessor) Init(opts *ep.ProcessingOptions, nonFlagArgs []string) error {
s.opts = opts
s.bodyRewrite = "this is a replacement body."

var (
i int
bodyRewrite string
)

nArgs := len(nonFlagArgs)
for ; i < nArgs-1; i++ {
if nonFlagArgs[i] == kbodyRewrite {
break
}
}

if i == nArgs {
log.Printf("the argument: 'body-rewrite' is missing, use the default.\n")
return nil
}

bodyRewrite = nonFlagArgs[i+1]

if len(bodyRewrite) > 0 {
s.bodyRewrite = bodyRewrite
log.Printf("the body rewrite is: %s\n", s.bodyRewrite)
}

return nil
}

func (s *bodyRewriteRequestProcessor) Finish() {}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/projectsesame/envoy-extproc-payloadlimit-demo-go
module github.com/projectsesame/envoy-extproc-bodyRewrite-demo-go

go 1.21

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type processor interface {
}

var processors = map[string]processor{
"payload-limit": &payloadLimitRequestProcessor{},
"body-rewrite": &bodyRewriteRequestProcessor{},
}

func parseArgs(args []string) (port *int, opts *ep.ProcessingOptions, nonFlagArgs []string) {
Expand Down
102 changes: 0 additions & 102 deletions payload-limit.go

This file was deleted.

0 comments on commit 37dd170

Please sign in to comment.