dream_mock_server/controllers/stream_controller
stream_controller.gleam - Mock streaming endpoints
Provides various streaming endpoints for testing Dream’s HTTP client. Each endpoint demonstrates different streaming behaviors and patterns.
Values
pub fn index(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Index action - displays available endpoints (streaming and non-streaming)
pub fn stream_binary(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Binary streaming - Raw binary data
Demonstrates non-text streaming.
pub fn stream_burst(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Burst streaming - Random burst pattern with 5-10 chunks
Demonstrates variable chunk count and timing for testing robustness.
pub fn stream_deflate(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Deflate-compressed streaming - 5 chunks, deflate-compressed as one stream
pub fn stream_drop(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Drop streaming - sends 2 chunks then crashes to close the socket
Simulates a server that drops the connection mid-stream. The yielder sends 2 valid chunks then panics, which kills the handler process and abruptly closes the TCP socket. This triggers httpc’s {error, Reason} path (e.g., socket_closed_remotely) instead of the normal stream_end path.
pub fn stream_error(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Error streaming - 3 chunks then fails
Demonstrates error handling mid-stream. Note: This returns a 500 status but still sends some chunks first.
pub fn stream_fast(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Fast streaming - 10 chunks at 100ms intervals
Demonstrates fast streaming for testing quick response handling.
pub fn stream_gzip(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Gzip-compressed streaming - 5 chunks, gzip-compressed as one stream
pub fn stream_huge(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Huge streaming - 100 chunks for memory/performance testing
Demonstrates large response streaming.
pub fn stream_json(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
JSON streaming - Stream of JSON objects
Demonstrates structured data streaming.
pub fn stream_slow(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Slow streaming - 5 chunks at 2s intervals
Demonstrates slow streaming for testing timeout handling.
pub fn stream_unknown_encoding(
request: request.Request,
context: context.EmptyContext,
services: router.EmptyServices,
) -> response.Response
Streaming with unknown Content-Encoding: br (raw passthrough)