Use mimeparse for Accept parsing/matching

瀏覽次數:2 次
跳到第一則未讀訊息

Ryan Tomayko

未讀,
2009年1月23日 清晨6:57:352009/1/23
收件者: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

未讀,
2009年1月23日 上午9:23:172009/1/23
收件者: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

未讀,
2009年1月23日 上午9:42:582009/1/23
收件者: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

回覆所有人
回覆作者
轉寄
0 則新訊息