Add remote mcp server sdk (#1946)

This commit is contained in:
澄潭
2025-03-24 22:11:45 +08:00
committed by GitHub
parent f5d20b72e0
commit d9f16f7d5e
17 changed files with 1337 additions and 13 deletions

View File

@@ -25,6 +25,11 @@ import (
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm"
)
type HttpCallNotify interface {
HttpCallStart(uint32)
HttpCallEnd(uint32)
}
type ResponseCallback func(statusCode int, responseHeaders http.Header, responseBody []byte)
type HttpClient interface {
@@ -108,7 +113,9 @@ func HttpCall(cluster Cluster, method, rawURL string, headers [][2]string, body
}
headers = append(headers, [2]string{":method", method}, [2]string{":path", path}, [2]string{":authority", authority})
requestID := uuid.New().String()
_, err = proxywasm.DispatchHttpCall(cluster.ClusterName(), headers, body, nil, timeout, func(numHeaders, bodySize, numTrailers int) {
httpCallNotify := cluster.HttpCallNotify()
var callID uint32
callID, err = proxywasm.DispatchHttpCall(cluster.ClusterName(), headers, body, nil, timeout, func(numHeaders, bodySize, numTrailers int) {
respBody, err := proxywasm.GetHttpCallResponseBody(0, bodySize)
if err != nil {
proxywasm.LogCriticalf("failed to get response body: %v", err)
@@ -135,8 +142,12 @@ func HttpCall(cluster Cluster, method, rawURL string, headers [][2]string, body
proxywasm.LogDebugf("http call end, id: %s, code: %d, normal: %t, body: %s",
requestID, code, normalResponse, respBody)
callback(code, headers, respBody)
httpCallNotify.HttpCallEnd(callID)
})
proxywasm.LogDebugf("http call start, id: %s, cluster: %s, method: %s, url: %s, headers: %#v, body: %s, timeout: %d",
requestID, cluster.ClusterName(), method, rawURL, headers, body, timeout)
if err == nil {
httpCallNotify.HttpCallStart(callID)
proxywasm.LogDebugf("http call start, id: %s, cluster: %s, method: %s, url: %s, headers: %#v, body: %s, timeout: %d",
requestID, cluster.ClusterName(), method, rawURL, headers, body, timeout)
}
return err
}