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

Function applyBody

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

Source from the content-addressed store, hash-verified

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