MCPcopy Create free account
hub / github.com/massCodeIO/massCode / executeHttpRequest

Function executeHttpRequest

src/main/ipc/handlers/http.ts:382–504  ·  view source on GitHub ↗
(
  payload: HttpExecutePayload,
)

Source from the content-addressed store, hash-verified

380}
381
382async function executeHttpRequest(
383 payload: HttpExecutePayload,
384): Promise<HttpExecuteResult> {
385 const variables = resolveEnvironmentVariables(payload.environmentId)
386 const interpolated = interpolateRequest(payload.request, variables)
387
388 const headersWithAuth = applyAuth(interpolated.auth, interpolated.headers)
389 const headersObj = toHeadersObject(headersWithAuth)
390 const built = buildBody(
391 interpolated.bodyType,
392 interpolated.body,
393 interpolated.formData,
394 )
395
396 const hasContentType = Object.keys(headersObj).some(
397 k => k.toLowerCase() === 'content-type',
398 )
399 if (!hasContentType && built.contentType) {
400 headersObj['Content-Type'] = built.contentType
401 }
402
403 let finalUrl: string
404 try {
405 finalUrl = buildUrl(interpolated.url, interpolated.query)
406 }
407 catch (error) {
408 return {
409 status: null,
410 statusText: '',
411 headers: [],
412 body: '',
413 bodyKind: 'text',
414 durationMs: 0,
415 sizeBytes: 0,
416 truncated: false,
417 error: error instanceof Error ? error.message : 'Invalid URL',
418 }
419 }
420
421 const timeoutMs = payload.timeoutMs ?? DEFAULT_TIMEOUT_MS
422 const controller = new AbortController()
423 const timer = setTimeout(() => controller.abort(), timeoutMs)
424 const startedAt = Date.now()
425 const startedAtPerf = performance.now()
426
427 try {
428 const response = await undiciRequest(finalUrl, {
429 method: interpolated.method,
430 headers: headersObj,
431 body: built.body as Dispatcher.DispatchOptions['body'],
432 signal: controller.signal,
433 maxRedirections: 5,
434 ...(payload.skipCertificateVerification
435 ? { dispatcher: insecureCertificateDispatcher }
436 : {}),
437 })
438
439 const { buffer, sizeBytes, truncated } = await readBodyCapped(

Callers 1

registerHttpHandlersFunction · 0.85

Calls 12

interpolateRequestFunction · 0.85
applyAuthFunction · 0.85
toHeadersObjectFunction · 0.85
buildBodyFunction · 0.85
buildUrlFunction · 0.85
readBodyCappedFunction · 0.85
toHeaderEntriesFunction · 0.85
getContentTypeFunction · 0.85
detectBodyKindFunction · 0.85
appendHistoryFunction · 0.85
formatHttpRequestErrorFunction · 0.85

Tested by

no test coverage detected