MCPcopy Create free account
hub / github.com/electric-sql/electric / toFetchRequest

Function toFetchRequest

packages/agents-runtime/src/create-handler.ts:781–804  ·  view source on GitHub ↗
(req: IncomingMessage)

Source from the content-addressed store, hash-verified

779}
780
781async function toFetchRequest(req: IncomingMessage): Promise<Request> {
782 const body = await readBody(req)
783 const host =
784 typeof req.headers.host === `string` ? req.headers.host : `localhost`
785 const url = new URL(req.url ?? `/`, `http://${host}`)
786 const headers = new Headers()
787
788 for (const [name, value] of Object.entries(req.headers)) {
789 if (Array.isArray(value)) {
790 for (const item of value) {
791 headers.append(name, item)
792 }
793 continue
794 }
795 if (value === undefined) continue
796 headers.set(name, value)
797 }
798
799 return new Request(url, {
800 method: req.method,
801 headers,
802 body: body.length > 0 ? Buffer.from(body) : undefined,
803 })
804}
805
806async function sendNodeResponse(
807 res: ServerResponse,

Callers 1

onEnterFunction · 0.85

Calls 5

readBodyFunction · 0.70
setMethod · 0.65
entriesMethod · 0.45
appendMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected