MCPcopy Create free account
hub / github.com/middleapi/orpc / deserializeBody

Function deserializeBody

packages/standard-server-peer/src/codec.ts:354–373  ·  view source on GitHub ↗
(headers: StandardHeaders, body: unknown, buffer: Uint8Array | undefined)

Source from the content-addressed store, hash-verified

352}
353
354async function deserializeBody(headers: StandardHeaders, body: unknown, buffer: Uint8Array | undefined): Promise<StandardBody> {
355 const contentType = flattenHeader(headers['content-type'])
356 const contentDisposition = flattenHeader(headers['content-disposition'])
357
358 if (typeof contentDisposition === 'string') {
359 const filename = getFilenameFromContentDisposition(contentDisposition) ?? 'blob'
360 return new File(buffer === undefined ? [] : [buffer], filename, { type: contentType })
361 }
362
363 if (contentType?.startsWith('multipart/form-data')) {
364 const tempRes = new Response(buffer, { headers: { 'content-type': contentType } })
365 return tempRes.formData()
366 }
367
368 if (contentType?.startsWith('application/x-www-form-urlencoded') && typeof body === 'string') {
369 return new URLSearchParams(body)
370 }
371
372 return body
373}
374
375/**
376 * A 16-byte sentinel of 0xFF values guaranteed never to collide with UTF-8 JSON text,

Callers 2

decodeRequestMessageFunction · 0.85
decodeResponseMessageFunction · 0.85

Calls 2

flattenHeaderFunction · 0.90

Tested by

no test coverage detected