I''m taking a stab at creating a parser to parse the server response using the mongrel parser as a base. Never having used a parser like Ragel before in my life, I''d like some input on the following for parsing an http server response. This is part of my modified version of http11_parser.rl. In particular what would be better than using ''any'' to match the status text? http_number = (digit+ "." digit+) ; HTTP_Version = ("HTTP/" http_number) >mark %http_version ; Http_status_code = (digit){3} >mark %http_status_code ; Http_status_text = any* >mark %http_status_text ; Request_Line = (HTTP_Version " " Http_status_code " " Http_status_text CRLF) ; field_name = (token -- ":")+ >start_field %write_field; field_value = any* >start_value %write_value; message_header = field_name ":" " "* field_value :> CRLF; Request = Request_Line (message_header)* ( CRLF @done); Chris
Ok I have a working parser for server responses based on the mongrel parser. But I''m trying to decide the best way to structure it so it will co-exist nicely with the mongrel parser when used in the same application. The main thing I''m trying to decide is what to do with all the variables that the mongrel parser puts into globals, but that the server response parser also needs. I know what would work for me, but maybe someone else might want to use this code also when I''m done so I''d like some feedback on it. My first reaction is to just not define any globals in the server parser and access everything from HttpParams. Thoughts? Also, the grammer I posted had a problem, but I figured it out and it appears to be working fine. Chris
On Tue, 31 Oct 2006 13:41:26 -0800 snacktime <snacktime at gmail.com> wrote:> I''m taking a stab at creating a parser to parse the server response > using the mongrel parser as a base. Never having used a parser like > Ragel before in my life, I''d like some input on the following for > parsing an http server response. This is part of my modified version > of http11_parser.rl. In particular what would be better than using > ''any'' to match the status text? >Already did that. It''s in RFuzz: http://rfuzz.rubyforge.org/ Including chunked encoding. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://safari.oreilly.com/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
On 10/31/06, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> On Tue, 31 Oct 2006 13:41:26 -0800 > snacktime <snacktime at gmail.com> wrote: > > > I''m taking a stab at creating a parser to parse the server response > > using the mongrel parser as a base. Never having used a parser like > > Ragel before in my life, I''d like some input on the following for > > parsing an http server response. This is part of my modified version > > of http11_parser.rl. In particular what would be better than using > > ''any'' to match the status text? > > > > Already did that. It''s in RFuzz: > > http://rfuzz.rubyforge.org/ > > Including chunked encoding.Ah very cool, saves me some work, although I was having fun learning to use Ragel.
Should probably ask just in case. Is there a version of the mongrel parser laying around that sticks everything in instance vars like rfuzz does? Chris
On Tue, 31 Oct 2006 21:00:01 -0800 snacktime <snacktime at gmail.com> wrote:> Should probably ask just in case. Is there a version of the mongrel > parser laying around that sticks everything in instance vars like > rfuzz does? >Nope, since nobody would use it anyway. Remember Mongrel has to talk to whatever the different framework authors cook up, which turns out to be a hash wrapped in half a cgi.rb sort of thing. With RFuzz I can do what I want so it''s much cleaner. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://safari.oreilly.com/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.