X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=c2135ef1105ae96e85f0f39db1a32240b7ee5929;hp=342362c07959b21353d7334867277d4f285f9b45;hb=90fca0675b1694e69b8e431c989343855cbd125d;hpb=cd1b58b84ff354e3fc2a7d2c8fd548a7b59fe138 diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index 342362c..c2135ef 100644 --- a/Network/HTTP/Lucu/Chunk.hs +++ b/Network/HTTP/Lucu/Chunk.hs @@ -1,35 +1,37 @@ +{-# LANGUAGE + UnicodeSyntax + #-} module Network.HTTP.Lucu.Chunk - ( chunkHeaderP -- Num a => Parser a - , chunkFooterP -- Parser () - , chunkTrailerP -- Parser Headers + ( chunkHeader + , chunkFooter + , chunkTrailer ) 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 - extension - crlf - - let [(len, _)] = readHex hexLen - return len +import Control.Applicative +import Data.Attoparsec.Char8 +import Data.Bits +import Data.Default +import Network.HTTP.Lucu.Headers +import Network.HTTP.Lucu.Parser.Http + +chunkHeader ∷ (Integral a, Bits a) ⇒ Parser a +{-# INLINEABLE chunkHeader #-} +chunkHeader = do len ← hexadecimal + extension + crlf + return len where - extension :: Parser () - extension = do many $ do char ';' - token - char '=' - token <|> quotedStr - return () - - -chunkFooterP :: Parser () -chunkFooterP = crlf >> return () - - -chunkTrailerP :: Parser Headers -chunkTrailerP = headersP + extension ∷ Parser () + extension + = skipMany ( char ';' *> + token *> + char '=' *> + (token <|> quotedStr) ) + +chunkFooter ∷ Parser () +{-# INLINE chunkFooter #-} +chunkFooter = crlf + +chunkTrailer ∷ Parser Headers +{-# INLINE chunkTrailer #-} +chunkTrailer = def