(->sse-response ring-request {:keys [status] :as opts})
Returns a ring response that will start a SSE stream.
The status code will be either 200 or the user provided one.
Specific SSE headers are set automatically, the user provided ones will be
merged. The response body is a sse generator implementing
ring.core.protocols/StreamableResponseBody
.
In sync mode, the connection is closed automatically when the handler is done running. You need to explicitely close it in rinc async.
Opts:
:status
: status for the HTTP response, defaults to 200:headers
: Ring headers map to add to the responseon-open
: Mandatory callback (fn [sse-gen] ...) called when the generator
is ready to send.on-close
: callback (fn [sse-gen] ...) called right after the generator
has closed it's connection.on-exception
: callback called when sending a SSE event throwswrite-profile
: write profile for the connection
defaults to basic-profile
When it comes to write profiles, the SDK provides:
You can also take a look at the starfederation.datastar.clojure.adapter.common
namespace if you want to write your own profiles.
Returns a ring response that will start a SSE stream. The status code will be either 200 or the user provided one. Specific SSE headers are set automatically, the user provided ones will be merged. The response body is a sse generator implementing `ring.core.protocols/StreamableResponseBody`. In sync mode, the connection is closed automatically when the handler is done running. You need to explicitely close it in rinc async. Opts: - `:status`: status for the HTTP response, defaults to 200 - `:headers`: Ring headers map to add to the response - [[on-open]]: Mandatory callback (fn [sse-gen] ...) called when the generator is ready to send. - [[on-close]]: callback (fn [sse-gen] ...) called right after the generator has closed it's connection. - [[on-exception]]: callback called when sending a SSE event throws - [[write-profile]]: write profile for the connection defaults to [[basic-profile]] When it comes to write profiles, the SDK provides: - [[basic-profile]] - [[buffered-writer-profile]] - [[gzip-profile]] - [[gzip-buffered-writer-profile]] You can also take a look at the `starfederation.datastar.clojure.adapter.common` namespace if you want to write your own profiles.
Basic write profile using temporary [[StringBuilder]]s and no compression.
Basic write profile using temporary [[StringBuilder]]s and no compression.
Write profile using a permanent [[BufferedWriter]] and no compression.
Write profile using a permanent [[BufferedWriter]] and no compression.
Default on-exception
callback, it returns true
on [[IOException]] which
closes, the generator. It rethrows the exception wrapped with ex-infor
otherwise.
Default [[on-exception]] callback, it returns `true` on [[IOException]] which closes, the generator. It rethrows the exception wrapped with `ex-infor` otherwise.
Write profile using a permanent [[BufferedWriter]] and gzip compression.
Write profile using a permanent [[BufferedWriter]] and gzip compression.
Write profile using temporary [[StringBuilder]]s and gzip compression.
Write profile using temporary [[StringBuilder]]s and gzip compression.
SSE option key:
Callback (fn [sse-gen & args] ...)
called just after the SSE connection is
closed. More specifically this callback is called when:
When this callback is called it is already not possible to send events anymore. It is called synchronously in the same thread that initiates the closing process.
Args:
sse-gen
: the closed SSE generatorReturn value: The return value isn't used.
Exception behavior:
While closing the sse-gen
several exceptions may be caught:
These exceptions are rethrown wrapped in an ex-info
. To get at these see
[[get-closing-exceptions]].
SSE option key: Callback `(fn [sse-gen & args] ...)` called just after the SSE connection is closed. More specifically this callback is called when: - [[starfederation.datastar.clojure.api/close-sse!]] is called explicitely - the sse-gen detects that the connection is closed by the client. This detection depends on the ring adapter being used. Http-kit AsyncChannel detects a broken connection by itself and calls on-close. With the ring generic adapter, the default behavior is to close the connection when a [[java.io.IOException]] is thrown sending an event. When this callback is called it is already not possible to send events anymore. It is called synchronously in the same thread that initiates the closing process. Args: - `sse-gen`: the closed SSE generator - Depending on the adapter used other arguments may be passed, see doc for the adapter you are using. Return value: The return value isn't used. Exception behavior: While closing the `sse-gen` several exceptions may be caught: - one while closing the underlying output stream - one executing this callback These exceptions are rethrown wrapped in an `ex-info`. To get at these see [[get-closing-exceptions]].
SSE option key:
Callback (fn [sse-gen e ctx] ...)
that will be called when an exception is
thrown sending an event.
Args:
sse-gen
: the SSEGenratore
: the exceptionctx
: context information about the exception, a map whose keys are:
:sse-gen
: the sse generator throwing:event-type
: type of the event that failed:data-lines
: data lines for this event:opts
: options used when sendingReturned value: A truthy value means the sse-gen must close itself.
Exception behavior: Exception thrown here aren't caught.
Defaults to default-on-exception
which will close the sse-gen
on
IOException or rethrow otherwise.
SSE option key: Callback `(fn [sse-gen e ctx] ...)` that will be called when an exception is thrown sending an event. Args: - `sse-gen`: the SSEGenrator - `e`: the exception - `ctx`: context information about the exception, a map whose keys are: - `:sse-gen`: the sse generator throwing - `:event-type`: type of the event that failed - `:data-lines`: data lines for this event - `:opts`: options used when sending Returned value: A truthy value means the sse-gen must close itself. Exception behavior: Exception thrown here aren't caught. Defaults to [[default-on-exception]] which will close the `sse-gen` on IOException or rethrow otherwise.
SSE option key:
Mandatory callback (fn [sse-gen] ...)
called when the SSE connection is
open.
It is called synchronously as soon as the connection is ready. This means that you can block the webserver's thread from here.
Args:
sse-gen
: the SSE generator, ready to send eventsReturn value: The return value isn't used.
Exception behavior: Exception thrown here aren't caught.
SSE option key: Mandatory callback `(fn [sse-gen] ...)` called when the SSE connection is open. It is called synchronously as soon as the connection is ready. This means that you can block the webserver's thread from here. Args: - `sse-gen`: the SSE generator, ready to send events Return value: The return value isn't used. Exception behavior: Exception thrown here aren't caught.
SSE option key:
This option allows a user to control the way SSE events are assembled and sent. It take a write profile which is a map whose keys are:
SSE option key: This option allows a user to control the way SSE events are assembled and sent. It take a write profile which is a map whose keys are: - [[wrap-output-stream]] - [[write!]] - [[content-encoding]] (optional if you don't use compression)
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |