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

Function applyBody

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

Source from the content-addressed store, hash-verified

207 });
208
209const applyBody = async (
210 request: HttpClientRequest.HttpClientRequest,
211 headers: Headers,
212 body: BodyInit | null | undefined,
213): Promise<HttpClientRequest.HttpClientRequest> => {
214 if (body == null) return request;
215 const contentType = headers.get("content-type") ?? undefined;
216 if (typeof body === "string") return HttpClientRequest.bodyText(request, body, contentType);
217 if (body instanceof URLSearchParams) {
218 return HttpClientRequest.bodyText(
219 request,
220 body.toString(),
221 contentType ?? "application/x-www-form-urlencoded;charset=UTF-8",
222 );
223 }
224 if (body instanceof Uint8Array)
225 return HttpClientRequest.bodyUint8Array(request, body, contentType);
226 if (body instanceof ArrayBuffer) {
227 return HttpClientRequest.bodyUint8Array(request, new Uint8Array(body), contentType);
228 }
229 const bytes = new Uint8Array(await new Response(body).arrayBuffer());
230 return HttpClientRequest.bodyUint8Array(request, bytes, contentType);
231};
232
233const abortError = (signal: AbortSignal): unknown => {
234 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