GithubHelp home page GithubHelp logo

mosn / proxy-wasm-go-host Goto Github PK

View Code? Open in Web Editor NEW
57.0 15.0 20.0 19.28 MB

WebAssembly for Proxies (Golang host implementation)

License: Apache License 2.0

Go 99.18% C++ 0.70% Makefile 0.12%

proxy-wasm-go-host's Introduction

WebAssembly for Proxies (GoLang host implementation)

The GoLang implementation for proxy-wasm, enabling developer to run proxy-wasm extensions in Go.

Run Example

  • build and run host
cd example
go run .
  • send http request
curl http://127.0.0.1:2045/
  • host log
receive request /
print header from server host, User-Agent -> [curl/7.64.1]
print header from server host, Accept -> [*/*]
[http_wasm_example.cc:33]::onRequestHeaders() print from wasm, onRequestHeaders, context id: 2
[http_wasm_example.cc:38]::onRequestHeaders() print from wasm, Accept -> */*
[http_wasm_example.cc:38]::onRequestHeaders() print from wasm, User-Agent -> curl/7.64.1

references

proxy-wasm-go-host's People

Contributors

antjack avatar codefromthecrypt avatar evacchi avatar lawrshen avatar moonshining avatar spacewander avatar taoyuanyuan avatar zhenjunma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxy-wasm-go-host's Issues

Imports/exports don't match expected Proxy-Wasm ABI versions.

Hello!

It was pointed out to me (see: proxy-wasm/proxy-wasm-rust-sdk#104) that Proxy-Wasm Go Host doesn't expose all Proxy-Wasm ABI v0.1.0 hostcalls.

Looking at the code, neither imports nor exports match the specification, e.g. host exports proxy_dispatch_http_call and imports proxy_on_plugin_start, but those don't exists in any of the existing versions (ABI v0.1.0, v0.2.0 or v0.2.1).

I believe that the source of the confusion might be the work-in-progress specification for vNEXT in proxy-wasm/spec, although even that doesn't define proxy_on_plugin_start, so it's unclear to me what's the source for your v1 and v2.

Note that there is no documention for either ABI v0.1.0, v0.2.0 or v0.2.1, so the code in Envoy and Proxy-Wasm SDKs is effectively the specification for those versions.

Change example to use currently maintained ABI (0.2)

Currently, the example points users the wrong way as no SDK is maintaining 0.1 anymore. Is it ok if I change it to something maintained? Ex tinygo with 0.2?

cc @taoyuanyuan @antJack

Ex. here's the current plugin used in tests ported to a currently maintained SDK in go

package main

import (
	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
)

// build main with `tinygo build -o main.wasm -scheduler=none -target=wasi ./main.go`
func main() {
	proxywasm.SetVMContext(&vmContext{})
}

type vmContext struct {
	// Embed the default VM context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultVMContext
}

// NewPluginContext overrides types.DefaultVMContext.
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
	return &pluginContext{}
}

type pluginContext struct {
	// Embed the default plugin context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultPluginContext
}

// NewHttpContext overrides types.DefaultPluginContext.
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
	return &httpHeaders{contextID: contextID}
}

type httpHeaders struct {
	// Embed the default http context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultHttpContext
	contextID uint32
}

// OnHttpRequestHeaders overrides types.DefaultHttpContext.
func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
	proxywasm.LogDebugf("print from wasm, onRequestHeaders, context id: %d", ctx.contextID)

	hs, err := proxywasm.GetHttpRequestHeaders()
	if err != nil {
		proxywasm.LogCriticalf("failed to get request headers: %v", err)
	}

	for _, h := range hs {
		proxywasm.LogInfof("print from wasm, %s -> %s", h[0], h[1])
	}
	return types.ActionContinue
}

Drop ABI v0.1.0

Per #10 the current code doesn't properly implement v0.1.0, and worse that version isn't really used or maintained anymore. I suggest focusing effort on maintained ABI. Notably this should also drop "wasi_unstable" for "wasi_snapshot_preview1" as that's what's in use by current compilers.

Until this is dropped implementing another host impl is too much low value work, as it is porting for unused and unmaintable ABI.

@taoyuanyuan @antJack FYI I'm pausing efforts until this is done as I am way over budget already and there's no value proceeding if we have to support an incorrect implementation of an unused ABI version.

When call ProxyOnRequestHeaders get wrong action

action

cd example and replace the wasm file to new file which handles HTTP headers like this. Then go run . run the example.

expected behaviour

If the header hit, Action::Pause will be returned from wasm side. ActionPause will be returned by the function ProxyOnRequestHeaders.

actual behaviour

Regardless of whether the expected header appears. ActionContinue will be returned by the function ProxyOnRequestHeaders

about the code

I noticed that the action ProxyOnRequestHeaders returned is actually from CallWasmFunction, and res is ignored.

Whether action should be ignored, the value of res should be converted into action format and returned. And what is a.Imports.Wait() actually do, is there any example for it?

Not able to add header element.

I am trying to add a header element to the request OnHttpRequestHeaders. It's not working or an error. Sample call - proxywasm.AddHttpRequestHeader("Debug", "1"), After this call context return back to the caller no instruction are executed.

go get mosn.io/proxy-wasm-go-host/proxywasm/common is failing

I am trying to use this module in my proxy code, while I am running go get I get the following error -
#go get mosn.io/proxy-wasm-go-host/proxywasm/common
#go get: module mosn.io/proxy-wasm-go-host@upgrade found (v0.1.0), but does not contain package mosn.io/proxy-wasm-go-host/proxywasm/common

err: "proxy_set_buffer_bytes" is not exported in module "env"

When wasm implements the ResponseBody function and is called using v2, an error will be reported

func (ctx *httpContext) OnHttpResponseBody(numHeaders int, endOfStream bool) types.Action {
	proxywasm.ReplaceHttpResponseBody([]byte("proxywasm.ReplaceHttpResponseBody"))
	return types.ActionContinue
}

[wazero][instance] Start failed to instantiate module, err: "proxy_set_buffer_bytes" is not exported in module "env"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.