Git Product home page Git Product logo

servant-websockets's People

Contributors

ch1bo avatar moesenle avatar ondrap avatar ondrejslamecka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

servant-websockets's Issues

Is there any way to get notified when client disconnects

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.

Firefox won't connect with servant 0.15

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)

WebSocket has fewer instances than Raw

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]).

Allow configurable ConnectionOptions

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.

WebSocket with Servant.Auth: overlapping instance for HasServer

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?

Successful connections are logged as 500 errors

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.

Build failure with servant 0.16

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)
   |                                               

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.