GithubHelp home page GithubHelp logo

Comments (5)

antJack avatar antJack commented on July 20, 2024

I've noticed that, thanks. That's exactly a question for your rust example. And maybe we should consider the return value of both proxy_on_request_headers and a.Imports.Wait() on ABIContext.ProxyOnRequestHeaders, instead of simply taking the return value of a.Imports.Wait(), and ignoring proxy_on_request_headers.

a.Imports.Wait() is actually for async callout from the wasm module. For example, if you make a HTTP callout in your wasm module, then the go-host should launch the HTTP call, and wait for a response synchronously, and that's the Wait function exactly do. In this case, the ActionContinue from proxy_on_request_headers should be ignored, since you're waiting for the response of the previous HTTP callout to make further decision.

from proxy-wasm-go-host.

Taction avatar Taction commented on July 20, 2024

Thanks for your reply. When I stress test the code, whether it uses the original wasm or my own, memory leaks will occur. Do you have any ideas about it?

from proxy-wasm-go-host.

antJack avatar antJack commented on July 20, 2024

try pprof, may need to add the following pprof section into mosn config:
image

from proxy-wasm-go-host.

Taction avatar Taction commented on July 20, 2024

Thanks, I'll try it later.

from proxy-wasm-go-host.

codefromthecrypt avatar codefromthecrypt commented on July 20, 2024

@Taction this module is incompatible with any current version of proxy-wasm. The only thing I could get to build is an old version of 0.1.0. I would suggest working with mosn project leads to allow an alternate implementation in mosn. That or we add https://http-wasm.io/http-handler/ and leave proxy-wasm alone. Since you are an end user I think best you help drive action here. cc @taoyuanyuan

package main

import (
	"strconv"

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

// build main like below with proxy-wasm-go-sdk v0.0.14 which works with
// TinyGo 0.19.0 (which works with Go 1.16).
//
//	tinygo build -o main.wasm -scheduler=none -target=wasi -tags 'abi_010' --no-debug ./main.go
//
// Note: Old tooling is needed because mosn.io/proxy-wasm-go-host v2 is
// incompatible with the proxy-wasm specification.
func main() {
	proxywasm.SetNewHttpContext(newHttpContext)
}

type myHttpContext struct {
	// you must embed the default context so that you need not to re-implement all the methods by yourself
	proxywasm.DefaultHttpContext
	contextID uint32
}

func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext {
	return &myHttpContext{contextID: contextID}
}

func (ctx *myHttpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
	key := "Wasm-Context"
	err := proxywasm.SetHttpRequestHeader(key, strconv.Itoa(int(ctx.contextID)))
	if err != nil {
		proxywasm.LogCritical("failed to set request header: " + key)
	}
	return types.ActionContinue
}

from proxy-wasm-go-host.

Related Issues (10)

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.