mirror of
https://github.com/alibaba/higress.git
synced 2026-05-21 11:17:28 +08:00
Add remote mcp server sdk (#1946)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user