Skip to content

feat: Support ldcli's dev-server #94

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

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/LaunchDarkly/Server/Network/Streaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module LaunchDarkly.Server.Network.Streaming (streamingThread) where

import Control.Applicative (many)
import Control.Applicative (many, (<|>))
import Control.Concurrent (threadDelay)
import Control.Exception (throwIO)
import Control.Monad (mzero, void)
Expand All @@ -27,7 +27,7 @@ import System.Clock (Clock (Monotonic), TimeSpec (TimeSpec), getTime)
import System.Random (Random (randomR), newStdGen)
import System.Timeout (timeout)

import LaunchDarkly.AesonCompat (KeyMap)
import LaunchDarkly.AesonCompat (KeyMap, emptyObject)
import LaunchDarkly.Server.Config.ClientContext (ClientContext (..))
import LaunchDarkly.Server.Config.HttpConfiguration (HttpConfiguration (..), prepareRequest)
import LaunchDarkly.Server.DataSource.Internal (DataSourceUpdates (..))
Expand All @@ -39,7 +39,7 @@ data PutBody = PutBody
{ flags :: !(KeyMap Flag)
, segments :: !(KeyMap Segment)
}
deriving (Generic, Show, FromJSON)
deriving (Generic, Show)

data PathData d = PathData
{ path :: !Text
Expand All @@ -53,6 +53,12 @@ data PathVersion = PathVersion
}
deriving (Generic, Show, FromJSON)

instance FromJSON PutBody where
parseJSON = withObject "PutBody" $ \o -> do
flags <- o .: "flags"
segments <- o .:? "segments" .!= emptyObject
pure $ PutBody {flags = flags, segments = segments}

instance FromJSON a => FromJSON (PathData a) where
parseJSON = withObject "Put" $ \o -> do
pathData <- o .: "data"
Expand Down Expand Up @@ -98,7 +104,7 @@ processField (fieldName, fieldValue) event = case fieldName of

parseEvent :: Parser SSE
parseEvent = do
fields <- many (many comment >> parseField >>= pure)
fields <- concat <$> many ((comment >> pure []) <|> fmap (: []) parseField)
endOfLineSSE
let event = foldr processField (SSE "" "" mzero mzero) fields
if T.null (name event) || T.null (buffer event) then parseEvent else pure event
Expand Down
Loading