proxy-wasm-go-sdk icon indicating copy to clipboard operation
proxy-wasm-go-sdk copied to clipboard

Better practice for multiple DispatchHttpCall

Open MengjiaLiang opened this issue 3 years ago • 0 comments

Hi there,

I am trying to migrate our Lua-based EnvoyFilter to be proxy-wasm-based EnvoyFilter.

I am now facing an issue related to the callback model for DispatchHttpCall, hence, wondering if any experts can share with some better practices.

Originally, our Lua script will do

1.   HTTPCall to service A
2.  Populate headers based on the response from A
3.  Another HTTPCall to service B
4.  Populate headers based on the response from B

This workflow can be run sequentially in a single Lua script.

When it comes to the proxy-wasm world, I found this pattern is not working

func (ctx *HttpContext) OnHttpRequestHeaders(int, bool) types.Action {
	if _, err := proxywasm.DispatchHttpCall(
		LocationServiceHost,
		headers,
		nil,
		nil,
		DefaultHTTPCallTimeout,
		createGetLocationCallBack(ctx),
	); err != nil {
		proxywasm.LogCriticalf("dispatch httpcall %s failed: %v", path, err)
		return err
	}
       
       // some operations to get the values from context and set header.

       return types.ActionContinue
}

I checked the examples in this repository, seems the OnHttpRequestHeaders should return types.ActionPause instead, and the operations to set headers should be moved into the call back function.

One thing I am curious about here, is there a way that we can dispatch multiple HTTP calls inside OnHttpRequestHeaders?

If I take multiple HTTP calls here, is that possible to synchronize the callback functions to resume the request when all the callback functions are finished?

Looking forward to any thoughts from experts. Appreciate that in advance!

MengjiaLiang avatar Aug 10 '22 20:08 MengjiaLiang