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

Function applyBody

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

Source from the content-addressed store, hash-verified

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