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

Function applyBody

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

Source from the content-addressed store, hash-verified

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