Cookie parsing

28 views
Skip to first unread message

Dae San Hwang

unread,
Aug 27, 2008, 7:11:05 PM8/27/08
to ebb...@googlegroups.com
Ry,

I was looking into "flow_parser.c" to add HTTP Cookie parsing to flow
but I guess it requires changes on "ebb_request struct"? (hint: Please
help!)

daesan

ry dahl

unread,
Aug 28, 2008, 4:55:09 AM8/28/08
to ebb...@googlegroups.com
hi daesan,

you should be able to do it without touching ebb_request_parser.rl / .h
at least that has been my intention with ebb_request_parser.

i'd throw a hook in header_field which checks for a string "cookie".
remember the header index (which is the last argument to the callback,
currently unused in flow). then in header_value, when the index is the
same, you can parse the input. header_value also does not use the
header_index field (last argument).

i'd just use ivars in rb_request to keep state info (as I am doing in
the rest of flow_parser.c)

hope that helps -
ry

ry dahl

unread,
Aug 28, 2008, 4:59:25 AM8/28/08
to ebb...@googlegroups.com
daesan,

I made a parser for query strings last year. it may or may not be helpful
http://rubyforge.org/pipermail/mongrel-development/2007-September/000005.html
(query strings and cookie strings are pretty similar)

ry

Dae San Hwang

unread,
Sep 10, 2008, 1:24:58 PM9/10/08
to ebb...@googlegroups.com
Ry,

It turns out that header parsing by flow(ebb) is off by one index that
whichever is the last header is being quietly thrown away. In my case,
"Cookie" header was being dropped which mislead me into believing that
ebb_request_parser_execute was parsing each header separately and
"Cookie" header was being ignored.

Specifically, if the http request is the following,

GET / HTTP/1.1
User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3
OpenSSL/0.9.7l zlib/1.2.3
Host: localhost:5000
Accept: */*
Cookie: session_id=1000


"header_field" function is called four times. First time, filed and
value are both nil. Second time, field and value are "HTTP_USER_AGENT"
and "curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/
0.9.7l zlib/1.2.3". Third time, field and value are "HTTP_HOST" and
"localhost:5000". Fourth time, field and value are "HTTP_ACCEPT" and
"*/*".

"header_field" is not called for "Cookie: session_id=1000" header.

Knowing that you are away now, I am not sure what I can do with this
bug. I guess I should start learning Ragel..

How's the trip by the way? :)

daesan

PS: I didn't mean to include cookie string parsing into flow. I think
that job belongs to the web framework. ;)

ry dahl

unread,
Sep 10, 2008, 1:32:35 PM9/10/08
to ebb...@googlegroups.com
Hey Daesan,

Yikes - sounds like a real bug! I doubt this is in the parser because
I have fairly extensive parsing tests. I would examine flow_parser.c
carefully
http://github.com/ry/flow/tree/master/ext/flow_parser.c#L99
this function needs refactoring anyway
Yes, I'm still away (just happen to be at the computer right now)

ry

On Wed, Sep 10, 2008 at 1:24 PM, Dae San Hwang <li...@daesan.com> wrote:
>
> Ry,
>

Dae San Hwang

unread,
Sep 10, 2008, 1:49:36 PM9/10/08
to ebb...@googlegroups.com
Cool. I didn't expect such a prompt reply. :)

But "header_field" is a callback function called from
"ebb_request_parse.c", right? Only thing it can be doing wrong seems
to be getting "@field_in_progress" variable.

I can't seem to find where "@field_in_progress" gets assigned. Is this
some internal variable used by ragel?

daesan

Dae San Hwang

unread,
Sep 10, 2008, 4:11:20 PM9/10/08
to ebb...@googlegroups.com
Ry,

I think I've fixed this bug. Please review it when you have time. (http://github.com/daesan/flow/tree/master
)

Would it be possible to have one callback function from
"ebb_request_parse.c" to process both 'header field' and 'header
value' at the same time? I think code would be cleaner that way, if
that is possible at all.

Have a nice trip and thanks for the tip while you are traveling! :)

Best,

daesan

ry dahl

unread,
Sep 10, 2008, 5:15:42 PM9/10/08
to ebb...@googlegroups.com
Hi Daesan,
Sorry - review will have to wait until October. You should be able to
handle everything without changes to ebb_request_parser.c (which is
generated from ebb_request_parser.rl)
ry

On Wed, Sep 10, 2008 at 4:11 PM, Dae San Hwang <li...@daesan.com> wrote:
>
> Ry,
>

Dae San Hwang

unread,
Sep 11, 2008, 2:12:43 AM9/11/08
to ebb...@googlegroups.com
That's alright. I just wanted to make sure I am not breaking anything
and it seems to work. ;)

daesan

Reply all
Reply to author
Forward
0 new messages