Created
August 23, 2012 05:12
-
-
Save xrl/3432712 to your computer and use it in GitHub Desktop.
mongrel2 parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
import qualified Data.Attoparsec as AP | |
import qualified Data.ByteString as BS | |
import qualified Data.ByteString.Char8 as C8 | |
sp = 32 | |
co = 58 | |
main = do | |
contents <- readFile "test.txt" | |
AP.parseTest p (C8.pack contents) | |
p = do | |
uuid <- AP.takeTill (== sp) | |
_ <- AP.word8 sp | |
conn_id <- AP.takeTill(== sp) | |
_ <- AP.word8 sp | |
url <- AP.takeTill(== sp) | |
_ <- AP.word8 sp | |
header_length_bs <- AP.takeTill(== co) | |
let header_length = ((read . C8.unpack) header_length_bs) :: Int | |
_ <- AP.word8 sp | |
header_data <- AP.take header_length | |
return (uuid,conn_id,url,header_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment