--- #hide
+{-# LANGUAGE
+ UnicodeSyntax
+ #-}
module Network.HTTP.Lucu.Chunk
- ( chunkHeaderP -- Num a => Parser a
- , chunkFooterP -- Parser ()
- , chunkTrailerP -- Parser Headers
+ ( chunkHeaderP
+ , chunkFooterP
+ , chunkTrailerP
)
where
-
-import Network.HTTP.Lucu.Headers
-import Network.HTTP.Lucu.Parser
-import Network.HTTP.Lucu.Parser.Http
-import Numeric
-
-
-chunkHeaderP :: Num a => Parser a
-chunkHeaderP = do hexLen <- many1 hexDigit
+import Control.Applicative
+import Data.Attoparsec.Char8
+import Data.Bits
+import Network.HTTP.Lucu.Headers
+import Network.HTTP.Lucu.Parser.Http
+
+chunkHeaderP ∷ (Integral a, Bits a) ⇒ Parser a
+{-# INLINEABLE chunkHeaderP #-}
+chunkHeaderP = do len ← hexadecimal
extension
crlf
-
- let [(len, _)] = readHex hexLen
return len
where
- extension :: Parser ()
- extension = do many $ do char ';'
- token
- char '='
- token <|> quotedStr
- return ()
-
-
-chunkFooterP :: Parser ()
-chunkFooterP = crlf >> return ()
+ extension ∷ Parser ()
+ extension
+ = skipMany ( char ';' *>
+ token *>
+ char '=' *>
+ (token <|> quotedStr) )
+chunkFooterP ∷ Parser ()
+chunkFooterP = crlf
-chunkTrailerP :: Parser Headers
+chunkTrailerP ∷ Parser Headers
chunkTrailerP = headersP