1 {-# LANGUAGE OverloadedStrings #-}
2 module Language.Haskell.LSP.Test.Parsing where
4 import qualified Data.ByteString.Lazy.Char8 as B
7 getAllMessages :: Handle -> IO [B.ByteString]
13 msg <- getNextMessage h
15 (msg :) <$> getAllMessages h
17 -- | Fetches the next message bytes based on
18 -- the Content-Length header
19 getNextMessage :: Handle -> IO B.ByteString
21 headers <- getHeaders h
22 case read . init <$> lookup "Content-Length" headers of
23 Nothing -> error "Couldn't read Content-Length header"
24 Just size -> B.hGet h size
26 addHeader :: B.ByteString -> B.ByteString
27 addHeader content = B.concat
29 , B.pack $ show $ B.length content
35 getHeaders :: Handle -> IO [(String, String)]
38 let (name, val) = span (/= ':') l
39 if null val then return [] else ((name, drop 2 val) :) <$> getHeaders h