]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Chunk.hs
Chunked input now works!
[Lucu.git] / Network / HTTP / Lucu / Chunk.hs
diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs
new file mode 100644 (file)
index 0000000..342362c
--- /dev/null
@@ -0,0 +1,35 @@
+module Network.HTTP.Lucu.Chunk
+    ( chunkHeaderP  -- Num a => Parser a
+    , chunkFooterP  -- Parser ()
+    , chunkTrailerP -- Parser Headers
+    )
+    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
+    where
+      extension :: Parser ()
+      extension = do many $ do char ';'
+                               token
+                               char '='
+                               token <|> quotedStr
+                     return ()
+
+
+chunkFooterP :: Parser ()
+chunkFooterP = crlf >> return ()
+
+
+chunkTrailerP :: Parser Headers
+chunkTrailerP = headersP