Gert Cuykens
Gert Cuykens

Reputation: 7155

Warp Wai WebSockets intercept

import Network.Wai.Application.Static (staticApp, defaultWebAppSettings)
import Network.Wai.Handler.WebSockets (intercept)
import Network.Wai.Handler.Warp (runSettings, defaultSettings, 
                                 settingsIntercept, settingsPort)

main :: IO ()
main = do
    let s = defaultSettings {settingsPort=9160, settingsIntercept=intercept app}
    runSettings s $ staticApp $ defaultWebAppSettings "www"

1) What I would like to know is if warp can distinguish between a websocket request and static request on the same port to prevent overhead by only running the static or the intercept app depending on the request.

http://hackage.haskell.org/packages/archive/wai-websockets/1.3.1/doc/html/src/Network-Wai-Handler-WebSockets.html

2) The above source file uses conduit, does that mean it is safe to use a strict ByteString for my websocket receiveData without worrying about potentially large amounts of incoming data that could overflow my memory or should I use a lazy ByteString instead?

Note that you can not chunk a websocket as in http chunked transfer encoding.

Upvotes: 2

Views: 868

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31315

  1. If a websocket request is received, then the application itself will never be called, and your websocket handler will take over immediately.

  2. Without seeing your code, there's no way to guarantee that you're not reading it too much information. But it is possible to use a strict ByteString the way you're describing.

Upvotes: 1

Related Questions