Skip to content

Instantly share code, notes, and snippets.


tobias/core.clj Secret

Created Apr 15, 2016
What would you like to do?
(ns add-extensions.core
(:require [ :as io]
[immutant.web :as web]
[immutant.web.async :as async]
[immutant.web.undertow :as utow])
(:import org.projectodd.wunderboss.web.undertow.async.websocket.UndertowWebsocket
(defn extension []
(proxy [PerMessageDeflateHandshake] []
(accept [ex]
;; just to know we've actually registered something w/o having
;; to use deflate
(println "PerMessageDeflateHandshake used")
(proxy-super accept ex))))
(defn echo
(if (:websocket? req)
(async/as-channel req
:on-open (partial println "OPEN")
:on-message async/send!)
{:status 200
:body (slurp (io/resource "index.html"))}))
(defn -main [& args]
;; create an HttpHandler around the ring handler
(let [handler (utow/http-handler echo)]
;; look up the WebSocketProtocolHandshakeHandler it uses
(.getAttachment handler UndertowWebsocket/HANDSHAKE_ATTACHMENT_KEY)
(web/run handler)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment