Class: BunResponse
Defined in: service-core/src/http/bun/BunAdapters.ts:82
Adapts a buffered/streamed set of response calls to the framework-agnostic HttpResponse
interface, bridging them into a Fetch API Response that Bun.serve()'s fetch() handler
resolves and returns.
Two modes:
- Buffered (default):
end()/json()/send()finalize the body and resolveresponseReadywith a single completeResponse. - Streaming:
flushHeaders()/write()construct aReadableStream-backedResponseand resolveresponseReadyimmediately (before the body is fully known) so the client starts receiving bytes right away; furtherwrite()calls enqueue chunks,end()closes the stream.
Implements
Indexable
[
key:string]:any
Allow arbitrary per-response properties.
Constructors
Constructor
new BunResponse(
rawRequest):BunResponse
Defined in: service-core/src/http/bun/BunAdapters.ts:107
Parameters
rawRequest
Request
Returns
BunResponse
Properties
isHead
isHead:
boolean=false
Defined in: service-core/src/http/bun/BunAdapters.ts:93
Set to true for HEAD requests — body bytes must not be sent.
responseReady
readonlyresponseReady:Promise<Response>
Defined in: service-core/src/http/bun/BunAdapters.ts:105
Resolves once headers are known — either the full buffered Response, or a streaming one.
result?
optionalresult?:any
Defined in: service-core/src/http/bun/BunAdapters.ts:95
Intermediate result passed between middleware.
Implementation of
Accessors
headersSent
Get Signature
get headersSent():
boolean
Defined in: service-core/src/http/bun/BunAdapters.ts:122
Returns
boolean
Implementation of
statusCode
Get Signature
get statusCode():
number
Defined in: service-core/src/http/bun/BunAdapters.ts:118
Returns
number
Implementation of
writableEnded
Get Signature
get writableEnded():
boolean
Defined in: service-core/src/http/bun/BunAdapters.ts:126
Returns
boolean
Implementation of
Methods
abortStream()
abortStream(
err):void
Defined in: service-core/src/http/bun/BunAdapters.ts:261
Errors the underlying stream if it's still open. Used when a middleware chain throws after
streaming has already started and the Response has already been handed back to the client.
Parameters
err
any
Returns
void
end()
end(
data?):void
Defined in: service-core/src/http/bun/BunAdapters.ts:164
Parameters
data?
any
Returns
void
Implementation of
flushHeaders()
flushHeaders():
void
Defined in: service-core/src/http/bun/BunAdapters.ts:194
Flushes status and headers to the wire immediately without ending the response, via a
ReadableStream, and resolves responseReady right away so the client starts receiving
bytes before the rest of the middleware chain finishes. Required before streaming data
(e.g. SSE). Safe to call multiple times — only acts on the first call.
Returns
void
getHeader()
getHeader(
key):string|undefined
Defined in: service-core/src/http/bun/BunAdapters.ts:145
Parameters
key
string
Returns
string | undefined
Implementation of
json()
json(
data):void
Defined in: service-core/src/http/bun/BunAdapters.ts:149
Parameters
data
any
Returns
void
Implementation of
onAbort()
onAbort(
callback):void
Defined in: service-core/src/http/bun/BunAdapters.ts:226
Registers a callback to run when the client aborts the connection — either before any
response was sent (via the request's AbortSignal) or mid-stream (via the ReadableStream's
cancel callback).
Parameters
callback
() => void
Returns
void
onFinish()
onFinish(
handler):void
Defined in: service-core/src/http/bun/BunAdapters.ts:236
Registers a callback fired exactly once when the response lifecycle ends — a normal end(), a client abort, or a streaming abort. Fires immediately if the response has already finished. Handlers run fire-and-forget (via a resolved microtask) so slow/async work (e.g. a Redis write) never delays or blocks the actual response flush.
Parameters
handler
() => void | Promise<void>
Returns
void
Implementation of
send()
send(
data?):void
Defined in: service-core/src/http/bun/BunAdapters.ts:154
Parameters
data?
any
Returns
void
Implementation of
setHeader()
setHeader(
key,value):this
Defined in: service-core/src/http/bun/BunAdapters.ts:140
Parameters
key
string
value
string | number
Returns
this
Implementation of
status()
status(
code):this
Defined in: service-core/src/http/bun/BunAdapters.ts:135
Parameters
code
number
Returns
this
Implementation of
write()
write(
data):void
Defined in: service-core/src/http/bun/BunAdapters.ts:215
Writes a chunk to the response without ending it (streaming / SSE). Flushes headers on the first call if they haven't been sent yet.
Parameters
data
string | Buffer<ArrayBufferLike>
Returns
void