-
-
Save tobias/a82e004d0180cbc4db20c9f2f6bf7249 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns add-extensions.core | |
(:require [clojure.java.io :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 | |
io.undertow.websockets.extensions.PerMessageDeflateHandshake)) | |
(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 | |
[req] | |
(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)] | |
(.addExtension | |
;; look up the WebSocketProtocolHandshakeHandler it uses | |
(.getAttachment handler UndertowWebsocket/HANDSHAKE_ATTACHMENT_KEY) | |
(extension)) | |
(web/run handler))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment