moesenle / servant-websockets Goto Github PK
View Code? Open in Web Editor NEWLicense: BSD 3-Clause "New" or "Revised" License
License: BSD 3-Clause "New" or "Revised" License
Nice package! Thanks.
Warning: I'm fairly new to Haskell.
Right now, I assume an exception of some sort is thrown because a 500 error is returned and subsequently logged when a client disconnects.
I would like to either handle that exception myself or get notified of the disconnection. Either way, I'd rather that a 500 error wasn't sent/logged.
Thanks.
Hello,
I've run into the issue specific to just Firefox with servant 0.15.
This is an error is thrown in Firefox on new WebScoket()
Firefox can’t establish a connection to the server at ws://localhost:foo/bar
I've tested examples in master (using lts-9.0) and it works with servant version from this snapshot.
I've tested chrome with stackage updated to lts-12.26
and this case works as well.
table of compatibility:
lts-9.0 | lts-12.26 | |
---|---|---|
Chrome | OK | OK |
FireFox | OK | broken |
I have no idea what exactly this is about and how it can be fixed (at least not yet).
The issue can be tested by applying this patch
turboMaCk@3b133b0
and following:
$ stack build
$ stack exec websocket-stream
and opening index.html
in Firefox.
Firefox version: 64.0
OS: Mac/Linux (NixOS)
I don't understand the internals yet but it's clear that the WebSocket
type is lacking some instances that Raw
has. When trying to wrap servant-auth
's Auth
combinator around Raw
, things work fine. But if I wrap it around WebSocket
I get a No instance for (HasServer (AddSetCookieApi (AddSetCookieApi WebSocket)) '[CookieSettings, JWTSettings])
.
Would it be possible for ConnectionOptions
to be passed in?
Not sure how this would work since it's hidden behind a HasServer
instance
Edit: Nevermind, I realized this is configurable via a PendingConnection
.
Pairing Servant.Auth
authentication with a Servant.WebSockets
endpoint yields an overlapping instances error.
• Overlapping instances for HasServer
(Servant.Auth.Server.Internal.AddSetCookie.AddSetCookieApi
(Servant.Auth.Server.Internal.AddSetCookie.AddSetCookieApi
Servant.API.WebSocket.WebSocketPending))
'[Backend ByteString, CookieSettings, JWTSettings]
arising from a use of ‘hoistServerWithContext’
This error was mentioned in a comment in #2. Does anyone know how solve this or have an idea on how to start?
Hey, I have been using this library and noticed some inconvenient behavior when adding logging. When adding a logging middleware (any logging middleware should work), and then requesting a connection to the WebSocket, the logs will show a 500 error. The connection is successful, and no other issues seem to exist. I suspect there should an exception being raised somewhere but I am not really sure where.
To test this I used the example provided in the documentation in this library with a basic logger:
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import Network.WebSockets.Connection (PendingConnection, sendTextData, forkPingThread, acceptRequest)
import Servant.API.WebSocket (WebSocketPending)
import Control.Monad.IO.Class
import Control.Monad
import Data.ByteString.Char8
import Control.Concurrent
import Network.Wai.Middleware.RequestLogger
startApp :: IO ()
startApp = run 8080 app
app :: Application
app = logStdout $ serve api server
api :: Proxy WebSocketApi
api = Proxy
type WebSocketApi = "stream" :> WebSocketPending
server :: Server WebSocketApi
server = streamData
where
streamData :: MonadIO m => PendingConnection -> m ()
streamData pc = do
c <- liftIO $ acceptRequest pc
liftIO $ forkPingThread c 10
liftIO . forM_ [1..] $ \i ->
sendTextData c (pack $ show (i :: Int)) >> threadDelay 1000000
When connecting to the websocket, the log will show something like this:
127.0.0.1 - - [07/Feb/2022:09:05:21 -0500] "GET /stream HTTP/1.1" 500 - "" ""
where 500 - ""
is the response and it represents a HTTP 500 error.
Any help figuring this out is appreciated.
Building library for servant-websockets-1.1.0..
[1 of 2] Compiling Servant.API.WebSocket ( src/Servant/API/WebSocket.hs, dist/build/Servant/API/WebSocket.o )
src/Servant/API/WebSocket.hs:14:68: error:
Module ‘Servant.Server’ does not export ‘ServantErr(..)’
|
14 | import Servant.Server (HasServer (..), ServantErr (..), ServerT, runHandler)
| ^^^^^^^^^^^^^^^
src/Servant/API/WebSocket.hs:16:52: error:
Module
‘Servant.Server.Internal.RoutingApplication’
does not export
‘RouteResult(..)’
|
16 | import Servant.Server.Internal.RoutingApplication (RouteResult (..), runDelayed)
| ^^^^^^^^^^^^^^^^
src/Servant/API/WebSocket.hs:16:70: error:
Module
‘Servant.Server.Internal.RoutingApplication’
does not export
‘runDelayed’
|
16 | import Servant.Server.Internal.RoutingApplication (RouteResult (..), runDelayed)
|
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.