immutant.web.middleware

Ring middleware useful with immutant.web

wrap-development

(wrap-development handler)

Wraps stacktrace and reload middleware with the correct :dirs option set, but will toss an exception if either the passed handler isn’t a normal Clojure function or ring/ring-devel isn’t available on the classpath

wrap-session

(wrap-session handler)(wrap-session handler options)

Uses the session from either Undertow or, when deployed to an app server cluster such as WildFly or EAP, the servlet’s possibly-replicated HttpSession. By default, sessions will timeout after 30 minutes of inactivity.

Supported options:

  • :timeout The number of seconds of inactivity before session expires [1800]
  • :cookie-name The name of the cookie that holds the session key [“JSESSIONID”]

A :timeout value less than or equal to zero indicates the session should never expire.

When running embedded, i.e. not deployed to a WildFly/EAP container, another option is available:

  • :cookie-attrs A map of attributes to associate with the session cookie [nil]

And the following :cookie-attrs keys are supported:

  • :path - the subpath the cookie is valid for
  • :domain - the domain the cookie is valid for
  • :max-age - the maximum age in seconds of the cookie
  • :secure - set to true if the cookie requires HTTPS, prevent HTTP access
  • :http-only - set to true if the cookie is valid for HTTP and HTTPS only (ie. prevent JavaScript access)

Within WildFly/EAP, :cookie-attrs is ignored because a servlet context may only be configured at deployment. This means non-standard cookie configuration must be done in WEB-INF/web.xml.

wrap-websocket

(wrap-websocket handler key value & key-values)(wrap-websocket handler callbacks)

Middleware to attach websocket callbacks to a Ring handler.

The following callbacks are supported, where channel is an async channel, throwable is a Java exception, and message may be either a String or a byte[]:

  • :on-message (fn [channel message])
  • :on-open (fn [channel])
  • :on-close (fn [channel {:keys [code reason]}])
  • :on-error (fn [channel throwable])

If handler is nil, a 404 status will be returned for any non-websocket request. Also see immutant.web.async/as-channel.