zxyao145 opened a new issue, #9887:
URL: https://github.com/apache/apisix/issues/9887

   ### Description
   
   I am writing a wasm plugin with go, and we need to dynamically obtain 
relevant configuration information through HTTP requests in the plugin. 
However, I encountered the following error while using 
proxywasm.DispatchHttpCall:
   
   ```
   Error: error status returned by host: bad argument
   ```
   
   My source code is as follows:
   ```go
   
   func TestDispatchHttpCall() (string, error) {
        proxywasm.LogWarnf("TestDispatchHttpCall!")
        defer func() {
                if err := recover(); err != nil {
                        proxywasm.LogErrorf("TestDispatchHttpCall panic! %+v", 
err)
                }
        }()
   
        urlStr := "http://xxxx.com/api/healthz";
        uri, err := url.Parse(urlStr)
        if err != nil {
                proxywasm.LogErrorf("TestDispatchHttpCall url.Parse Error: 
%+v", err)
                return "", err
        }
   
        hs := [][2]string{}
        hs = append(hs, [2]string{":scheme", uri.Scheme})
        hs = append(hs, [2]string{"host", uri.Host})
        hs = append(hs, [2]string{":path", uri.Path})
        hs = append(hs, [2]string{":method", "GET"})
   
        var bodyCh = make(chan []byte)
        proxywasm.LogWarnf("TestDispatchHttpCall info: %s, %+v", uri.Host, hs)
        _, err = proxywasm.DispatchHttpCall(uri.Host, hs, nil, nil, 5000, 
func(numHeaders, bodySize, numTrailers int) {
                proxywasm.LogWarn("TestDispatchHttpCall callback!")
                bodyBytes, err := proxywasm.GetHttpCallResponseBody(0, bodySize)
                if err != nil {
                        proxywasm.LogErrorf("TestDispatchHttpCall callback 
Error: %+v", err)
                        return
                }
                bodyCh <- bodyBytes
                close(bodyCh)
        })
   
   
        if err != nil {
                // here will got the error
   +            proxywasm.LogErrorf("TestDispatchHttpCall Error: %+v", err)
                return "", err
        }
   
        select {
        case body := <-bodyCh:
                proxywasm.LogWarnf("TestDispatchHttpCall receive body! %s", "")
                var rspJson map[string]string
                err = json.Unmarshal(body, &rspJson)
                if err != nil {
                        proxywasm.LogErrorf("Error: %+v", err)
                        return "", err
                }
                proxywasm.LogWarnf("TestDispatchHttpCall receive rspJson %s", 
rspJson)
                return "", nil
        case <-time.After(time.Second * 2):
                return "", fmt.Errorf("call kc error")
        }
   }
   ```
   I have looked at the code for 
[forward-auth](https://github.com/apache/apisix/blob/master/t/wasm/forward-auth.go)
 and the logic should be the same for both. 
   
   Hope to receive your help, thank a lot!
   
   
   
   
   
    
   
   ### Environment
   
   - APISIX version (run `apisix version`): 3.2.0
   - Operating system (run `uname -a`): debian:bullseye-slim
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): nginx 
version: openresty/1.21.4.1 
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`): 3.4.18
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to