Liking cljdoc? Tell your friends :D

strojure.undertow.handler

Undertow HttpHandler functionality and library of standard handlers.

Undertow `HttpHandler` functionality and library of standard handlers.
raw docstring

as-arity-1-wrapperclj

(as-arity-1-wrapper f)

Converts 1-arity function (fn [handler]) to function (fn [obj]) returning handler wrapper (fn [handler] ...).

Converts 1-arity function `(fn [handler])` to function `(fn [obj])`
returning handler wrapper `(fn [handler] ...)`.
sourceraw docstring

as-arity-2-wrapperclj

(as-arity-2-wrapper f)

Converts 2-arity function (fn [handler obj]) to function (fn [obj]) returning handler wrapper (fn [handler] ...).

Converts 2-arity function `(fn [handler obj])` to function `(fn [obj])`
returning handler wrapper `(fn [handler] ...)`.
sourceraw docstring

define-typeclj

(define-type type {:keys [as-handler as-wrapper alias]})

Adds multimethods for declarative description of HTTP handlers.

  1. type A constant to distinguish specific handler, usually handler function itself.
  2. Options:
    • :as-handler The function (fn [obj] handler) to coerce obj to handler.
    • :as-wrapper The function (fn [obj] (fn [handler])) returning function to wrap another handler.
    • :alias The alias for the type, usually keyword.
Adds multimethods for declarative description of HTTP handlers.

1) `type` A constant to distinguish specific handler, usually handler function
          itself.
2) Options:
    - `:as-handler` The function `(fn [obj] handler)` to coerce `obj` to
                    handler.
    - `:as-wrapper` The function `(fn [obj] (fn [handler]))` returning
                    function to wrap another handler.
    - `:alias` The alias for the `type`, usually keyword.
sourceraw docstring

force-dispatchclj

(force-dispatch handler)

A HttpHandler that dispatches request if it is running in the io thread.

A HttpHandler that dispatches request if it is running in the io thread.
sourceraw docstring

graceful-shutdownclj

(graceful-shutdown next-handler)

Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully.

Returns a new handler that can be used to wait for all requests to finish
before shutting down the server gracefully.
sourceraw docstring

in-memory-session-managerclj

(in-memory-session-manager
  {:keys [session-id-generator deployment-name max-sessions
          expire-oldest-unused-session-on-max statistics-enabled]
   :or {max-sessions 0 expire-oldest-unused-session-on-max true}})

Return instance of InMemorySessionManager given configuration map.

Return instance of `InMemorySessionManager` given configuration map.
sourceraw docstring

pathclj

(path config)
(path default-handler {:keys [prefix exact cache-size]})

Returns a new path handler, with optional default handler. A HttpHandler that dispatches to a given handler based of a prefix match of the path. This only matches a single level of a request, e.g. if you have a request that takes the form: /foo/bar.

Arguments:

  • default-handler The handler that is invoked if there are no paths matched.

  • config The configuration map with options:

    • :prefix The map of path prefixes and their handlers.

      • If the path does not start with a / then one will be prepended.
      • The match is done on a prefix bases, so registering /foo will also match /foo/bar. Though exact path matches are taken into account before prefix path matches. So if an exact path match exists its handler will be triggered.
      • If / is specified as the path then it will replace the default handler.
    • :exact The map of exact paths and their handlers.

      • If the request path is exactly equal to the given path, run the handler.
      • Exact paths are prioritized higher than prefix paths.
    • :cache-size The cache size, unlimited by default, integer.

Example:

(handler/path {:prefix {"static" (handler/resource {...})}
               :exact {"ws" (handler/websocket {...})}})
Returns a new path handler, with optional default handler. A `HttpHandler`
that dispatches to a given handler based of a prefix match of the path. This
only matches a single level of a request, e.g. if you have a request that
takes the form: `/foo/bar`.

Arguments:

- `default-handler` The handler that is invoked if there are no paths matched.

- `config` The configuration map with options:

    - `:prefix` The map of path prefixes and their handlers.
        + If the path does not start with a `/` then one will be prepended.
        + The match is done on a prefix bases, so registering `/foo` will also
          match `/foo/bar`. Though exact path matches are taken into account
          before prefix path matches. So if an exact path match exists its handler
          will be triggered.
        + If `/` is specified as the path then it will replace the default handler.

    - `:exact` The map of exact paths and their handlers.
        + If the request path is exactly equal to the given path, run the handler.
        + Exact paths are prioritized higher than prefix paths.

    - `:cache-size` The cache size, unlimited by default, integer.

Example:

    (handler/path {:prefix {"static" (handler/resource {...})}
                   :exact {"ws" (handler/websocket {...})}})
sourceraw docstring

proxy-peer-addressclj

(proxy-peer-address next-handler)

Returns a new handler that sets the peer address based on the X-Forwarded-For and X-Forwarded-Proto headers.

This should only be used behind a proxy that always sets this header, otherwise it is possible for an attacker to forge their peer address.

Returns a new handler that sets the peer address based on the
`X-Forwarded-For` and `X-Forwarded-Proto` headers.

This should only be used behind a proxy that always sets this header,
otherwise it is possible for an attacker to forge their peer address.
sourceraw docstring

request-dumpclj

(request-dump next-handler)

Returns a handler that dumps requests to the log for debugging purposes.

Returns a handler that dumps requests to the log for debugging purposes.
sourceraw docstring

resourceclj

(resource resource-manager)
(resource next-handler resource-manager)

Returns a new resource handler with optional next handler that is called if no resource is found.

Function arguments:

  • next-handler The handler that is called if no resource is found.

  • resource-manager The instance of ResourceManager or resource manager configuration map.

    Resource manager configuration options:

    Configuration options of :class-path resource manager:

    • :prefix The prefix that is appended to resources that are to be loaded, string.
      • Default prefix is "public".

Example:

(handler/resource {:resource-manager :class-path
                   :prefix "public/static"})
Returns a new resource handler with optional next handler that is called if
no resource is found.

Function arguments:

- `next-handler` The handler that is called if no resource is found.

- `resource-manager` The instance of `ResourceManager` or resource manager
                     configuration map.

  Resource manager configuration options:

    - `:resource-manager` The type of configuration manager, keyword.
        + Used as `:type` in configuration passed to [[api.types/as-resource-manager]].

  Configuration options of `:class-path` resource manager:

    - `:prefix` The prefix that is appended to resources that are to be
                loaded, string.
        + Default prefix is "public".

Example:

    (handler/resource {:resource-manager :class-path
                       :prefix "public/static"})
sourceraw docstring

session-attachmentclj

(session-attachment next-handler
                    {:keys [session-manager session-config]
                     :or {session-manager {} session-config {}}})

Returns a new handler that attaches the session to the request. This handler is also the place where session cookie configuration properties are configured. Note: this approach is not used by Servlet, which has its own session handlers.

  1. next-handler The handler that is called after attaching session.

  2. Handler configuration map with options:

    • session-manager The instance of SessionManager or session manager configuration map. If not specified then InMemorySessionManager is used with default settings (see in-memory-session-manager).

    • session-config The instance of SessionConfig or session config configuration map. If not specified then SessionCookieConfig is used with default settings (see session-cookie-config).

Returns a new handler that attaches the session to the request. This handler
is also the place where session cookie configuration properties are
configured. Note: this approach is not used by Servlet, which has its own
session handlers.

1) `next-handler` The handler that is called after attaching session.

2) Handler configuration map with options:

    - `session-manager` The instance of `SessionManager` or session manager
      configuration map. If not specified then `InMemorySessionManager` is used
      with default settings (see [[in-memory-session-manager]]).

    - `session-config` The instance of `SessionConfig` or session config
      configuration map. If not specified then `SessionCookieConfig` is used
      with default settings (see [[session-cookie-config]]).
sourceraw docstring

(session-cookie-config {:keys [cookie-name path domain discard secure http-only
                               max-age comment]})

Returns instance of SessionCookieConfig given configuration map.

Returns instance of `SessionCookieConfig` given configuration map.
sourceraw docstring

simple-error-pageclj

(simple-error-page next-handler)

Returns a handler that generates an extremely simple no frills error page.

Returns a handler that generates an extremely simple no frills error page.
sourceraw docstring

virtual-hostclj

(virtual-host {:keys [host]})
(virtual-host default-handler config)

Returns a new virtual host handler, with optional default handler. A HttpHandler that implements virtual hosts based on the Host: http header.

Arguments:

  • default-handler The handler that is invoked if there are no hostnames matched.

  • config The configuration map with options:

    • :host The map of hostnames and their handlers.

Example:

(handler/virtual-host {:host {"static.localhost" (handler/resource {...})
                              "ws.localhost" (handler/websocket {...})})
Returns a new virtual host handler, with optional default handler.
A `HttpHandler` that implements virtual hosts based on the `Host:` http
header.

Arguments:

- `default-handler` The handler that is invoked if there are no hostnames
                    matched.

- `config` The configuration map with options:

    - `:host` The map of hostnames and their handlers.

Example:

    (handler/virtual-host {:host {"static.localhost" (handler/resource {...})
                                  "ws.localhost" (handler/websocket {...})})
sourceraw docstring

websocketclj

(websocket {:as callback :keys [on-connect on-message on-close on-error]})
(websocket callback)
(websocket next-handler
           {:as callback :keys [on-connect on-message on-close on-error]})
(websocket next-handler callback)

Returns a new web socket session handler with optional next handler to invoke if the web socket connection fails. A HttpHandler which will process the HttpServerExchange and do the actual handshake/upgrade to WebSocket.

Function arguments:

  • next-handler The handler that is invoked if there are no web socket headers.

  • callback The instance of the WebSocketConnectionCallback or callback configuration map.

    Callback configuration options:

    • :on-connect The function (fn [{:keys [callback exchange channel]}]).

      • Is called once the WebSocket connection is established, which means the handshake was successful.
    • :on-message The function (fn [{:keys [callback channel text data]}]).

      • Is called when listener receives a message.
      • The text message is provided in :text and binary message is provided in :data.
    • :on-close The function (fn [{:keys [callback channel code reason]}]).

    • :on-error The function (fn [{:keys [callback channel error]}]).

      • Is called on WebSocket connection error.
      • Default implementation just closes WebSocket connection.
Returns a new web socket session handler with optional next handler to invoke
if the web socket connection fails. A `HttpHandler` which will process the
`HttpServerExchange` and do the actual handshake/upgrade to WebSocket.

Function arguments:

- `next-handler` The handler that is invoked if there are no web socket
                 headers.

- `callback` The instance of the `WebSocketConnectionCallback` or callback
             configuration map.

  Callback configuration options:

    - `:on-connect` The function `(fn [{:keys [callback exchange channel]}])`.
        + Is called once the WebSocket connection is established, which means
          the handshake was successful.

    - `:on-message` The function `(fn [{:keys [callback channel text data]}])`.
        + Is called when listener receives a message.
        + The text message is provided in `:text` and binary message is
          provided in `:data`.

    - `:on-close` The function `(fn [{:keys [callback channel code reason]}])`.
        + Is called once the WebSocket connection is closed.
        + The `:code` is status code to close messages:
          http://tools.ietf.org/html/rfc6455#section-7.4

    - `:on-error` The function `(fn [{:keys [callback channel error]}])`.
        + Is called on WebSocket connection error.
        + Default implementation just closes WebSocket connection.
sourceraw docstring

wrap-handlerclj

(wrap-handler handler with)

Wraps handler chaining with sequence of handler wrappers in with.

Wraps `handler` chaining with sequence of handler wrappers in `with`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close