views:

172

answers:

1

Hello could somebody give me a start on how to parse the HTTP-protocol with scala 2.8 packrat-parsing?

I need to parse attached examplary HTTP Response into

  • ResponseStatusCode:Int
  • Headers:List[(String,String)]
  • Body: String, Array[Byte], CharBuffer or whatever

Short examplary usage of a Packrat-Parser very much appreciated. Thanks!

HTTP/1.1·200·OK(CR)(LF)
Date:·Thu,·27·May·2010·12:18:48·GMT(CR)(LF)
Server:·Apache(CR)(LF)
Vary:·Accept-Encoding,User-Agent(CR)(LF)
Connection:·close(CR)(LF)
Transfer-Encoding:·chunked(CR)(LF)
Content-Type:·text/html;·charset=utf-8(CR)(LF)
(CR)(LF)
... Hello World ..
+1  A: 

There are abundant on-line resources about using Scala's combinator parser library: http://bit.ly/atIzBG

Randall Schulz
I thought there were bigger differences between "old-school" parsers and the new packrat parsers.
hotzen
@hotzen: The Scala 2.8 combinator parser library adds PEG parsing and can memoize parse results for potential re-use when backtracking occurs. I don't see either of these as being pertinent to parsing HTTP responses. Perhaps I'm mistaken.
Randall Schulz
You are totally right but as this is a current parsing-job to be done, I thought I could have a look into the packrats...
hotzen
@hotzen: I still don't see this as a parsing problem. It's just an matter of decoding an unordered collection of key/value pairs. It can be done with parsing techniques and tools, but I still think that's excessive. And since it's not something you're doing for the sake of writing a parser, you should use an existing library (http://hc.apache.org/).
Randall Schulz