summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-24 14:04:55 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-24 14:04:55 -0400
commita6180f446dc97de56a2ed2e117c3be196d76f20b (patch)
treedf67729f2450850fc419474b9504915b0a771473
parent82375df3f48246e13e6c9a0c24d937a54d16359a (diff)
downloaddebug-me-a6180f446dc97de56a2ed2e117c3be196d76f20b.tar.gz
also enable compression in server
-rw-r--r--Server.hs2
-rw-r--r--WebSockets.hs15
2 files changed, 10 insertions, 7 deletions
diff --git a/Server.hs b/Server.hs
index 5467fbe..527ac02 100644
--- a/Server.hs
+++ b/Server.hs
@@ -93,7 +93,7 @@ server o = runSettings settings . app o =<< newServerState
defaultSettings
app :: ServerOpts -> TVar ServerState -> Application
-app o ssv = websocketsOr WS.defaultConnectionOptions (websocketApp o ssv) webapp
+app o ssv = websocketsOr connectionOptions (websocketApp o ssv) webapp
where
webapp _ respond = respond $
responseLBS status400 [] "Not a WebSocket request"
diff --git a/WebSockets.hs b/WebSockets.hs
index 6231298..c463c28 100644
--- a/WebSockets.hs
+++ b/WebSockets.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE OverloadedStrings, DeriveGeneric, GeneralizedNewtypeDeriving, FlexibleContexts, FlexibleInstances #-}
module WebSockets (
+ connectionOptions,
runClientApp,
clientApp,
protocolError,
@@ -29,9 +30,16 @@ import qualified Data.ByteString.Lazy as L
import Data.List
import Data.Monoid
+-- | Enable compression.
+connectionOptions :: ConnectionOptions
+connectionOptions = defaultConnectionOptions
+ { connectionCompressionOptions =
+ PermessageDeflateCompression defaultPermessageDeflate
+ }
+
runClientApp :: ClientApp () -> IO ()
runClientApp app = catchJust catchconnclosed
- (runClientWith "localhost" 8081 "/" connoptions [] app)
+ (runClientWith "localhost" 8081 "/" connectionOptions [] app)
(\_ -> return ())
where
-- For some reason, runClient throws ConnectionClosed
@@ -39,11 +47,6 @@ runClientApp app = catchJust catchconnclosed
catchconnclosed ConnectionClosed = Just ()
catchconnclosed _ = Nothing
- connoptions = defaultConnectionOptions
- { connectionCompressionOptions =
- PermessageDeflateCompression defaultPermessageDeflate
- }
-
-- | Make a client that sends and receives LogMessages over a websocket.
clientApp
:: Mode