-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Question] Requesting assistance adding support for ring-jetty9-adapter to Sente #89
Comments
hi @ptaoussanis sorry for late response being pretty busy during weekdays. I will experiment the upgrade by myself and come back to you if there is any updates/questions. |
No problem at all @sunng87, and thank you so much 🙏 |
I had a quick look into original jetty adapter, we will need to change (deftype JettyServerChanAdapter []
i/IServerChanAdapter
(ring-req->server-ch-resp [_ req callbacks-map]
(jetty/ws-upgrade-response
(server-ch-resp (jetty/ws-upgrade-request? req) callbacks-map)))) Just wrap the callbacks with And for I haven't been able to figure out how we can fallback to ajax when the request is not a websocket. We should be able to use the else branch of |
Hi @sunng87, thanks a lot for taking a look at this!
Can For example with http-kit: (defn handle-ring-req [ring-req]
(let [channel (org.httpkit.server/as-channel ring-req {})]
(future
;; Later, when application is ready ...
(Thread/sleep 2000)
(org.httpkit.server/send! channel
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Reply"}))
channel)) I think Immutant and Undertow also work like this. Can Or is this kind of async approach just fundamentally not currently possible? Thank you! |
it seems possible with ring's async api, check the async example in https://github.com/sunng87/ring-jetty9-adapter/blob/master/examples/rj9a/async.clj for websocket, it's like: (defn async-handler [request send-response _]
(send-response
(if (jetty/ws-upgrade-request? request)
;; if the request is a websocket upgrade, finish handshake
(jetty/ws-upgrade-response my-websocket-handler)
;; otherwise, use send-response with a ring response map
{:status 200 :body "hello"}))) We can create a channel implementation based on By the way, if you are using async handler, add option |
I see, thank you! So if I understand correctly, it seems the only way to currently provide an async HTTP response via I'll experiment with adding support for Ring's 3-arity async handlers to the next version of Sente 👍 This issue can be closed from my side, thanks again! |
Motivation: It looks like `ring-jetty9-adapter` might not currently be able to support async Ajax responses without 3-arity handler support, Ref. sunng87/ring-jetty9-adapter#89 And it looks like it *might* be reasonably easy to add support for 3-arity handlers to Sente without breaking any pre-existing users.
Motivation: It looks like `ring-jetty9-adapter` might not currently be able to support async Ajax responses without 3-arity handler support, Ref. sunng87/ring-jetty9-adapter#89 And it looks like it *might* be reasonably easy to add support for 3-arity handlers to Sente without breaking any pre-existing users.
Motivation: It looks like `ring-jetty9-adapter` might not currently be able to support async Ajax responses without 3-arity handler support, Ref. sunng87/ring-jetty9-adapter#89 And it looks like it *might* be reasonably easy to add support for 3-arity handlers to Sente without breaking any pre-existing users.
Thank you @ptaoussanis ! Let me know if you have any further questions! |
Hi Ning, thanks a lot for all your work on ring-jetty9-adapter!
Context
I maintain a Clojure/Script library called Sente. It provides an API to help make it easier for web apps to use WebSockets for client<->server communication.
Sente currently supports a number of Clojure web servers, incl. http-kit and ring-undertow-adapter.
Sente also previously supported ring-jetty9-adapter, but support seems to have been broken sometime around #59.
I'm currently working on a major upcoming update to Sente (v1.18), and it'd be great to get ring-jetty9-adapter support working again.
The trouble is that I've not yet had the opportunity to use ring-jetty9-adapter myself - and I haven't been able to find the info I need about the API online.
Would you maybe be available to assist with this?
Details of what's needed
To support a web-server like ring-jetty9-adapter, Sente needs an "adapter" that implements these 2 protocols.
Example implementations:
This is currently what I have:
Any assistance/advice would be very much appreciated, thanks!
Cheers :-)
The text was updated successfully, but these errors were encountered: