# `Pristine.Core.StreamResponse`
[🔗](https://github.com/nshkrdotcom/pristine/blob/pristine-v0.4.0/lib/pristine/core/stream_response.ex#L1)

Response wrapper for streaming HTTP responses.

Contains an enumerable stream of events instead of a complete body.
This is used for SSE (Server-Sent Events) and other streaming responses.

## Fields

  * `:stream` - An enumerable that yields events (required)
  * `:status` - HTTP status code (required)
  * `:headers` - Response headers as a map (required)
  * `:metadata` - Additional metadata (optional, defaults to empty map)

## Example

    %StreamResponse{
      stream: events,
      status: 200,
      headers: %{"content-type" => "text/event-stream"},
      metadata: %{request_id: "req_123"}
    }

## Usage

The stream can be consumed lazily:

    {:ok, response} = StreamTransport.stream(request, context)

    response.stream
    |> Stream.each(fn event ->
      IO.puts("Got event: #{inspect(event)}")
    end)
    |> Stream.run()

Or collected into a list:

    events = Enum.to_list(response.stream)

# `t`

```elixir
@type t() :: %Pristine.Core.StreamResponse{
  headers: map(),
  metadata: map(),
  status: integer(),
  stream: Enumerable.t()
}
```

# `cancel`

```elixir
@spec cancel(t()) :: :ok
```

Cancel the underlying stream when supported by the transport.

# `dispatch_event`

```elixir
@spec dispatch_event(Pristine.Streaming.Event.t(), module()) ::
  {:ok, term()} | {:error, term()} | term()
```

Dispatch a single event to a handler module based on its type.

# `dispatch_stream`

```elixir
@spec dispatch_stream(t(), module()) :: Enumerable.t()
```

Map a stream of events through a handler module.

# `last_event_id`

```elixir
@spec last_event_id(t()) :: String.t() | nil
```

Return the latest Last-Event-ID value when available.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
