MCPcopy Create free account
hub / github.com/atripati/ark / Execute

Method Execute

pkg/tools/http.go:196–308  ·  view source on GitHub ↗
(config HTTPToolConfig, params map[string]interface{})

Source from the content-addressed store, hash-verified

194 h.AllowedDomains = append(h.AllowedDomains, domain)
195}
196func (h *HTTPExecutor) Execute(config HTTPToolConfig, params map[string]interface{}) (string, error) {
197 reqURL := config.URL
198 for key, val := range params {
199 reqURL = strings.ReplaceAll(reqURL, "{"+key+"}", fmt.Sprintf("%v", val))
200 }
201 if err := h.checkDomain(reqURL); err != nil {
202 return "", err
203 }
204 var bodyBytes []byte
205 if len(config.RawBody) > 0 {
206 bodyBytes = config.RawBody
207 } else if config.Method != "GET" && config.Method != "DELETE" {
208 if config.Body == "json" {
209 var err error
210 bodyBytes, err = json.Marshal(params)
211 if err != nil {
212 return "", fmt.Errorf("ark/tools/http: marshal body: %w", err)
213 }
214 } else if config.Body != "" {
215 body := config.Body
216 for key, val := range params {
217 body = strings.ReplaceAll(body, "{"+key+"}", fmt.Sprintf("%v", val))
218 }
219 bodyBytes = []byte(body)
220 }
221 }
222 headers := make(map[string]string)
223 for k, v := range config.Headers {
224 for pk, pv := range params {
225 v = strings.ReplaceAll(v, "{"+pk+"}", fmt.Sprintf("%v", pv))
226 }
227 headers[k] = v
228 }
229 client := h.Client
230 if config.Timeout > 0 {
231 client = &http.Client{
232 Timeout: config.Timeout,
233 Transport: h.Client.Transport,
234 }
235 }
236 backoff := initialBackoff
237 var lastErr error
238
239 for attempt := 0; attempt <= maxRetries; attempt++ {
240 if attempt > 0 {
241 time.Sleep(backoff + jitter())
242 backoff = time.Duration(float64(backoff) * backoffFactor)
243 }
244
245 if h.Debug {
246 fmt.Printf("[ark/http] %s %s (attempt %d/%d)\n",
247 config.Method, reqURL, attempt+1, maxRetries+1)
248 }
249
250 var bodyReader io.Reader
251 if bodyBytes != nil {
252 bodyReader = bytes.NewReader(bodyBytes)
253 }

Callers

nothing calls this directly

Calls 5

checkDomainMethod · 0.95
jitterFunction · 0.85
parseRetryAfterFunction · 0.85
truncateFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected