wai-extra-3.1.17: Provides some basic WAI handlers and middleware.

Safe Haskell | None
Language | Haskell2010

Network.Wai.EventSource

Description

A WAI adapter to the HTML5 Server-Sent Events API.

If running through a proxy like Nginx you might need to add the headers:

    [ ("X-Accel-Buffering", "no"), ("Cache-Control", "no-cache")]

There is a small example using these functions in the `example` directory.

Synopsis

- data ServerEvent
  - = ServerEvent {
    - eventName :: Maybe Builder
    - eventId :: Maybe Builder
    - eventData :: [Builder]
    }
  - | CommentEvent {
    - eventComment :: Builder
    }
  - | RetryEvent {
    - eventRetry :: Int
    }
  - | CloseEvent
- eventSourceAppChan :: Chan ServerEvent -> Application
- eventSourceAppIO :: IO ServerEvent -> Application
- eventStreamAppRaw :: ((ServerEvent -> IO ()) -> IO () -> IO ()) -> Application

# Documentation

data ServerEvent #

Type representing a communication over an event stream. This can be an actual event, a comment, a modification to the retry timer, or a special "close" event indicating the server should close the connection.

Constructors

ServerEvent |

Fields

- eventName :: Maybe Builder
- eventId :: Maybe Builder
- eventData :: [Builder]

CommentEvent |

Fields

- eventComment :: Builder

RetryEvent |

Fields

- eventRetry :: Int

CloseEvent |

eventSourceAppChan :: Chan ServerEvent -> Application #

Make a new WAI EventSource application reading events from the given channel.

eventSourceAppIO :: IO ServerEvent -> Application #

Make a new WAI EventSource application reading events from the given IO action.

eventStreamAppRaw :: ((ServerEvent -> IO ()) -> IO () -> IO ()) -> Application #

Make a new WAI EventSource application with a handler that emits events.

Since: 3.0.28