]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Chunk.hs
Optimized as possible as I can.
[Lucu.git] / Network / HTTP / Lucu / Chunk.hs
1 -- #hide
2 module Network.HTTP.Lucu.Chunk
3     ( chunkHeaderP  -- Num a => Parser a
4     , chunkFooterP  -- Parser ()
5     , chunkTrailerP -- Parser Headers
6     )
7     where
8
9 import           Network.HTTP.Lucu.Headers
10 import           Network.HTTP.Lucu.Parser
11 import           Network.HTTP.Lucu.Parser.Http
12 import           Numeric
13
14
15 chunkHeaderP :: Num a => Parser a
16 chunkHeaderP = do hexLen <- many1 hexDigit
17                   extension
18                   crlf
19
20                   let [(len, _)] = readHex hexLen
21                   return len
22     where
23       extension :: Parser ()
24       extension = do many $ do char ';'
25                                token
26                                char '='
27                                token <|> quotedStr
28                      return ()
29 {-# SPECIALIZE chunkHeaderP :: Parser Int #-}
30
31
32 chunkFooterP :: Parser ()
33 chunkFooterP = crlf >> return ()
34
35
36 chunkTrailerP :: Parser Headers
37 chunkTrailerP = headersP