Skip to content

Commit a08246d

Browse files
committed
(fix): parse header field 'Content-Type'
1 parent 62b8bb5 commit a08246d

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lsp/src/Language/LSP/Server/Control.hs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import qualified Colog.Core as L
2020
import Colog.Core (LogAction (..), WithSeverity (..), Severity (..), (<&))
2121
import Control.Concurrent
2222
import Control.Concurrent.STM.TChan
23+
import Control.Applicative((<|>))
2324
import Control.Monad
2425
import Control.Monad.STM
2526
import Control.Monad.IO.Class
@@ -186,11 +187,34 @@ ioLoop ioLogger logger clientIn serverDefinition vfs sendMsg = do
186187
go (parse parser remainder)
187188

188189
parser = do
189-
_ <- string "Content-Length: "
190-
len <- decimal
191-
_ <- string _TWO_CRLF
190+
_ <- string "Content-"
191+
len <- lengthFirst <|> typeFirst
192192
Attoparsec.take len
193193

194+
lengthFirst = do
195+
len <- headLength
196+
_ <- string _ONE_CRLF
197+
<|> (headType >> string _ONE_CRLF)
198+
return len
199+
200+
typeFirst = do
201+
_ <- headType
202+
_ <- string "Content-"
203+
len <- headLength
204+
_ <- string _ONE_CRLF
205+
return len
206+
207+
headLength = do
208+
_ <- string "Length: "
209+
len <- decimal
210+
_ <- string _ONE_CRLF
211+
return len
212+
213+
headType = do
214+
skipWhile (/='\r')
215+
_ <- string _ONE_CRLF
216+
return ()
217+
194218
parseOne ::
195219
MonadIO m
196220
=> LogAction m (WithSeverity LspServerLog)
@@ -236,6 +260,8 @@ sendServer logger msgChan clientOut = do
236260
-- |
237261
--
238262
--
263+
_ONE_CRLF :: BS.ByteString
264+
_ONE_CRLF = "\r\n"
239265
_TWO_CRLF :: BS.ByteString
240266
_TWO_CRLF = "\r\n\r\n"
241267

0 commit comments

Comments
 (0)