Use mimeparse for Accept parsing/matching

2 views
Skip to first unread message

Ryan Tomayko

unread,
Jan 23, 2009, 6:57:35 AM1/23/09
to rack-...@googlegroups.com
I was pointed to this simple mimeparse library by bct on IRC the other
day and thought it would make a nice addition to Rack::Request and/or
Rack::Utils:

http://code.google.com/p/mimeparse/source/browse/trunk/mimeparse.rb

The entire lib is 216 lines with tests and supports parsing complex
Accept headers with, e.g., q= values and other parameters. There's also
"best_match" implementation:

irb> best_match(["application/xbel+xml", "text/xml"],
"text/*;q=0.5,*/*; q=0.1")
=> "text/xml"

I'll work with bct to get a patch together and open a ticket. In the
meantime, any thoughts?

Thanks
--
Ryan http://tomayko.com/about

Christoffer Sawicki

unread,
Jan 23, 2009, 9:23:17 AM1/23/09
to rack-...@googlegroups.com
On Fri, Jan 23, 2009 at 12:57 PM, Ryan Tomayko <r...@tomayko.com> wrote:
[...]

> I'll work with bct to get a patch together and open a ticket. In the
> meantime, any thoughts?

Some of that code could be generalized to also handle Accept-Encoding.
I took a look at MIMEParse when I wrote Rack::Deflater and IIRC all of
the functions are implemented in terms of parse_mime_type which
understands strings like "text/html" but not encoding names like
"gzip". If that could be parameterized, then I think most of
Rack::Utils.select_best_encoding could be thrown out.

Cheers,
Christoffer Sawicki
http://vemod.net/

Christian Neukirchen

unread,
Jan 23, 2009, 9:42:58 AM1/23/09
to rack-...@googlegroups.com
Ryan Tomayko <r...@tomayko.com> writes:

> I'll work with bct to get a patch together and open a ticket. In the
> meantime, any thoughts?

+1, I have a stipped down version in coset, but let's import the whole
thing if possible.

--
Christian Neukirchen <chneuk...@gmail.com> http://chneukirchen.org

Reply all
Reply to author
Forward
0 new messages