MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / applyBody

Function applyBody

packages/plugins/mcp/src/sdk/connection.ts:89–111  ·  view source on GitHub ↗
(
  request: HttpClientRequest.HttpClientRequest,
  headers: Headers,
  body: BodyInit | null | undefined,
)

Source from the content-addressed store, hash-verified

87 Object.fromEntries(headers.entries());
88
89const applyBody = async (
90 request: HttpClientRequest.HttpClientRequest,
91 headers: Headers,
92 body: BodyInit | null | undefined,
93): Promise<HttpClientRequest.HttpClientRequest> => {
94 if (body == null) return request;
95 const contentType = headers.get("content-type") ?? undefined;
96 if (typeof body === "string") return HttpClientRequest.bodyText(request, body, contentType);
97 if (body instanceof URLSearchParams) {
98 return HttpClientRequest.bodyText(
99 request,
100 body.toString(),
101 contentType ?? "application/x-www-form-urlencoded;charset=UTF-8",
102 );
103 }
104 if (body instanceof Uint8Array)
105 return HttpClientRequest.bodyUint8Array(request, body, contentType);
106 if (body instanceof ArrayBuffer) {
107 return HttpClientRequest.bodyUint8Array(request, new Uint8Array(body), contentType);
108 }
109 const bytes = new Uint8Array(await new Response(body).arrayBuffer());
110 return HttpClientRequest.bodyUint8Array(request, bytes, contentType);
111};
112
113const abortError = (signal: AbortSignal): unknown => {
114 if (signal.reason !== undefined) return signal.reason;

Callers 1

executeFunction · 0.85

Calls 3

toStringMethod · 0.80
arrayBufferMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected