Skip to content

Commit

Permalink
update according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
localvar committed Jul 14, 2021
1 parent 093f67b commit 7749885
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
8 changes: 1 addition & 7 deletions pkg/filter/wasm/hostfunc.go
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/megaease/easegress/pkg/logger"
)

////////////////////////////////////////////////////////////////////////////////
// helper functions

const wasmMemory = "memory"
Expand Down Expand Up @@ -152,8 +151,7 @@ func (vm *WasmVM) readHeaderFromWasm(addr int32) http.Header {
return http.Header(h)
}

////////////////////////////////////////////////////////////////////////////////
// request function
// request functions

func (vm *WasmVM) hostRequestGetRealIP() int32 {
v := vm.ctx.Request().RealIP()
Expand Down Expand Up @@ -294,7 +292,6 @@ func (vm *WasmVM) hostRequestSetBody(addr int32) {
vm.ctx.Request().SetBody(bytes.NewReader(body))
}

////////////////////////////////////////////////////////////////////////////////
// response functions

func (vm *WasmVM) hostResponseGetStatusCode() int32 {
Expand Down Expand Up @@ -362,7 +359,6 @@ func (vm *WasmVM) hostResponseSetBody(addr int32) {
vm.ctx.Response().SetBody(bytes.NewReader(body))
}

////////////////////////////////////////////////////////////////////////////////
// misc functions

func (vm *WasmVM) hostAddTag(addr int32) {
Expand All @@ -384,8 +380,6 @@ func (vm *WasmVM) hostLog(level int32, addr int32) {
}
}

////////////////////////////////////////////////////////////////////////////////

// importHostFuncs imports host functions into Wasm so that user-developed Wasm
// code can call these functions to interoperate with host.
func (vm *WasmVM) importHostFuncs(linker *wasmtime.Linker) {
Expand Down
14 changes: 2 additions & 12 deletions pkg/filter/wasm/wasm.go
Expand Up @@ -104,15 +104,6 @@ func (f *WasmFilter) Results() []string {
return results
}

func readWasmCodeFromFile(path string) ([]byte, error) {
f, e := os.Open(path)
if e != nil {
return nil, e
}
defer f.Close()
return io.ReadAll(f)
}

func readWasmCodeFromURL(url string) ([]byte, error) {
resp, e := http.DefaultClient.Get(url)
if e != nil {
Expand All @@ -127,8 +118,7 @@ func isURL(str string) bool {
// the LONG base64 encoded wasm code
for _, p := range []string{"http://", "https://"} {
if len(str) > len(p) {
s := strings.ToLower(str[:len(p)])
if strings.HasPrefix(s, p) {
if p == strings.ToLower(str[:len(p)]) {
return true
}
}
Expand All @@ -141,7 +131,7 @@ func (f *WasmFilter) readWasmCode() ([]byte, error) {
return readWasmCodeFromURL(f.spec.Code)
}
if _, e := os.Stat(f.spec.Code); e == nil {
return readWasmCodeFromFile(f.spec.Code)
return os.ReadFile(f.spec.Code)
}
return base64.StdEncoding.DecodeString(f.spec.Code)
}
Expand Down

0 comments on commit 7749885

Please sign in to comment.