Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wai-eventsource integration (turn a wai Application into ActionT) #80

Closed
pxqr opened this issue Mar 23, 2014 · 7 comments
Closed

wai-eventsource integration (turn a wai Application into ActionT) #80

pxqr opened this issue Mar 23, 2014 · 7 comments

Comments

@pxqr
Copy link

pxqr commented Mar 23, 2014

The problem I've encountered is that it's impossible to turn a wai Application into ActionT. Examples when we might need this includes both wai-eventsource and wai-websockets enabled applications, but lets consider the first one for a moment:

get "/:foo/updates" $ do 
  application (eventSourceAppChan myEventStream)

where application function is impossible to implement because ScottyResponse do not allow to return a plain old wai Response. The workaround is to set middleware with interceptor routing, which is pretty awkward.

@xich
Copy link
Member

xich commented Mar 23, 2014

Ah I can implement this. I'm not near a computer right now, but soon. Thanks for reporting!

@pxqr
Copy link
Author

pxqr commented Mar 30, 2014

I think the most promising way to fix this issue is to make ScottyResponse more general:

data ScottyResponse = SR
  { srStatus  :: Status
  , srHeaders :: ResponseHeaders -- ^ additional headers to append to the srResponse
  , srResponse :: Network.Wai.Response
  }

I guess it is possible to keep existing API the same. Do you have some considerations against this changes or any better ideas?

@crabmusket
Copy link

I've been looking at websockets and Scotty and my current solution is to handle websockets outside the Scotty app. It's not elegant but it works.

@bananu7
Copy link

bananu7 commented Aug 24, 2014

What's the status on that? I wrote a simple handler to test how that could be done:

sse :: T.Text -> ActionM ()
sse t = do
     setCorsHeader
     setHeader "Content-Type" "text/event-stream"
     setHeader "Cache-Control" "no-cache"
     setHeader "Connection" "keep-alive"
     raw $ encodeUtf8 t

And it works, but drops the connection nevertheless.

@liamoc
Copy link

liamoc commented Sep 9, 2014

Any progress on this issue?

@bsima
Copy link

bsima commented Jul 28, 2021

What's the status on that? I wrote a simple handler to test how that could be done:

sse :: T.Text -> ActionM ()
sse t = do
     setCorsHeader
     setHeader "Content-Type" "text/event-stream"
     setHeader "Cache-Control" "no-cache"
     setHeader "Connection" "keep-alive"
     raw $ encodeUtf8 t

And it works, but drops the connection nevertheless.

Why does this drop the connection despite having the keep-alive header?

@ocramz
Copy link
Collaborator

ocramz commented Sep 25, 2023

Well, now (since #233) you can have nested wai Applications under a Scotty route!

@ocramz ocramz closed this as completed Sep 25, 2023
@ocramz ocramz changed the title wai-eventsource integration wai-eventsource integration (turn a wai Application into ActionT) Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants