hijack method
Hijacks the connection associated with the AdapterRequest.
This passes control of the underlying communication channel (e.g., socket)
to the provided callback
. The callback receives a StreamChannel
for direct, low-level interaction with the client.
This is typically used for protocols like SSE or to support custom streaming scenarios where the standard request-response model, or web-socket communication is insufficient.
request
: The AdapterRequest whose connection is to be hijacked.callback
: The HijackCallback that will manage the hijacked connection.
For web-sockets see connect
Implementation
@override
Future<void> hijack(
covariant final IOAdapterRequest request,
final HijackCallback callback,
) async {
final socket =
await request._httpRequest.response.detachSocket(writeHeaders: false);
callback(StreamChannel(socket, socket));
}