Liking cljdoc? Tell your friends :D

hyper.ring

Hyper from plain Ring code: sign in and out from a route, and read a request's hyper session and endpoint from middleware.

Every function takes a request that has been through hyper's handler, or through hyper.ring.middleware/wrap-hyper, and throws for any other.

Hyper from plain Ring code: sign in and out from a route, and read a
request's hyper session and endpoint from middleware.

Every function takes a request that has been through hyper's handler, or
through `hyper.ring.middleware/wrap-hyper`, and throws for any other.
raw docstring

end-session!clj

(end-session! response req)

response with the request's session ended: the session's data is removed, the session cookie is deleted, and the session's open pages reconnect and reload into a fresh session. response as it is when the server holds no session for the request.

Example: ;; Sign out from a form post (defn sign-out [req] (-> (ring.util.response/redirect "/") (clear-auth-cookie) (h.ring/end-session! req)))

`response` with the request's session ended: the session's data is
removed, the session cookie is deleted, and the session's open pages
reconnect and reload into a fresh session.  `response` as it is when the
server holds no session for the request.

Example:
  ;; Sign out from a form post
  (defn sign-out [req]
    (-> (ring.util.response/redirect "/")
        (clear-auth-cookie)
        (h.ring/end-session! req)))
sourceraw docstring

endpointclj

(endpoint req)

The hyper endpoint the request is for: :action, :upload, :navigate or :events, or nil for page and app routes.

Example: ;; Answer a refused action with a 401 rather than a sign-in page (defn wrap-require-sign-in [handler] (fn [req] (cond (signed-in? req) (handler req) (h.ring/endpoint req) {:status 401} :else (ring.util.response/redirect "/sign-in"))))

The hyper endpoint the request is for: `:action`, `:upload`, `:navigate`
or `:events`, or nil for page and app routes.

Example:
  ;; Answer a refused action with a 401 rather than a sign-in page
  (defn wrap-require-sign-in [handler]
    (fn [req]
      (cond
        (signed-in? req)       (handler req)
        (h.ring/endpoint req)  {:status 401}
        :else                  (ring.util.response/redirect "/sign-in"))))
sourceraw docstring

rotate-session!clj

(rotate-session! response req)

response with the request's session given a new id, keeping its data and its tabs, and the session cookie set to the new id. Once the response has been written, the session's open pages reconnect: in the person's own browser they carry the new cookie and go on with their tab state, and in a browser that still holds the old id they reload into a fresh session. The old id names no session afterwards. response as it is when the server holds no session for the request.

Example: ;; OAuth callback (defn oauth-callback [req] (let [user (exchange-code! (get-in req [:params :code]))] (-> (ring.util.response/redirect "/") (set-auth-cookie user) (h.ring/rotate-session! req))))

`response` with the request's session given a new id, keeping its data
and its tabs, and the session cookie set to the new id.  Once the
response has been written, the session's open pages reconnect: in the
person's own browser they carry the new cookie and go on with their tab
state, and in a browser that still holds the old id they reload into a
fresh session.  The old id names no session afterwards.  `response` as it
is when the server holds no session for the request.

Example:
  ;; OAuth callback
  (defn oauth-callback [req]
    (let [user (exchange-code! (get-in req [:params :code]))]
      (-> (ring.util.response/redirect "/")
          (set-auth-cookie user)
          (h.ring/rotate-session! req))))
sourceraw docstring

session-idclj

(session-id req)

The id of the request's session when the server holds that session, else nil.

Example: (defn wrap-log-session [handler] (fn [req] (log/info "session" (h.ring/session-id req)) (handler req)))

The id of the request's session when the server holds that session, else
nil.

Example:
  (defn wrap-log-session [handler]
    (fn [req]
      (log/info "session" (h.ring/session-id req))
      (handler req)))
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close