Skip to content

Instantly share code, notes, and snippets.

@xrl
Created August 23, 2012 05:12
Show Gist options
  • Save xrl/3432712 to your computer and use it in GitHub Desktop.
Save xrl/3432712 to your computer and use it in GitHub Desktop.
mongrel2 parser
#!/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