MCPcopy
hub / github.com/vercel/next.js / toResponse

Method toResponse

packages/next/src/server/base-http/web.ts:105–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103 }
104
105 public async toResponse() {
106 // If we haven't called `send` yet, wait for it to be called.
107 if (!this.sent) await this.sendPromise.promise
108
109 const body = this.textBody ?? this.transformStream.readable
110
111 let bodyInit: BodyInit = body
112
113 // if the response is streaming, onClose() can still be called after this point.
114 const canAddListenersLater = typeof bodyInit !== 'string'
115 const shouldTrackBody = canAddListenersLater
116 ? true
117 : this.closeController.listeners > 0
118
119 if (shouldTrackBody) {
120 bodyInit = trackBodyConsumed(body, () => {
121 this.closeController.dispatchClose()
122 })
123 }
124
125 return new Response(bodyInit, {
126 headers: this.headers,
127 status: this.statusCode,
128 statusText: this.statusMessage,
129 })
130 }
131
132 public onClose(callback: () => void) {
133 if (this.closeController.isClosed) {

Callers 1

web.test.tsFile · 0.80

Calls 2

trackBodyConsumedFunction · 0.90
dispatchCloseMethod · 0.80

Tested by

no test coverage detected