From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.204.72.79 with SMTP id l15cs107454bkj; Sun, 14 Jun 2009 08:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.220.93.13 as permitted sender) client-ip=10.220.93.13; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.220.93.13 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.220.93.13]) by 10.220.93.13 with SMTP id t13mr263523vcm.26.1244993993014 (num_hops = 1); Sun, 14 Jun 2009 08:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received-spf:authentication-results:received :dkim-signature:domainkey-signature:mime-version:received :in-reply-to:references:from:date:message-id:subject:to:content-type :reply-to:sender:precedence:x-google-loop:mailing-list:list-id :list-post:list-help:list-unsubscribe:x-beenthere-env:x-beenthere; bh=Zbcx9Nfa9+K/t0Xa6DU8KQ/iDTAkV2xe8gzgLcX9eBQ=; b=4GP1V2w/fzPZzorkPEI41z10wrgZTEU/gkSoe/L63YHkjWpwLps9goXfPTi2D9qDKd INvHl5nAaRA3avgX49PmwfIrSpA3iGxuXvC3R9RS+F0z4YIBGeHXnHDdHMlh49/cOAgx zj47DyTFQ1z3E0N7vFXCfHMca8Eg4IwkacQMA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :dkim-signature:domainkey-signature:mime-version:in-reply-to :references:from:date:message-id:subject:to:content-type:reply-to :sender:precedence:x-google-loop:mailing-list:list-id:list-post :list-help:list-unsubscribe:x-beenthere-env:x-beenthere; b=UcPnoddQ6ciuv+ncfA6CMKqJNKZFzXx4rt0BANRazdlDG5upuSRRYuOjaoanW0xKrg C1Awlpi9Xz2nFcLI+ydZktaq+guYy4yDLsoGMvXwOcq5bu+87HGrDHdErU1AWeiofi4Q mhML9rZvoplpqtJCcNzhVZVLP2aijnZtptFvM= Received: by 10.220.93.13 with SMTP id t13mr35627vcm.26.1244993992506; Sun, 14 Jun 2009 08:39:52 -0700 (PDT) Received: by 10.230.2.2 with SMTP id 2gr1440vbh.0; Sun, 14 Jun 2009 08:39:43 -0700 (PDT) X-Sender: wycats@gmail.com X-Apparently-To: rack-devel@googlegroups.com Received: by 10.224.20.16 with SMTP id d16mr1288934qab.25.1244993982401; Sun, 14 Jun 2009 08:39:42 -0700 (PDT) Return-Path: Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.25]) by gmr-mx.google.com with ESMTP id 18si296755qyk.1.2009.06.14.08.39.41; Sun, 14 Jun 2009 08:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of wycats@gmail.com designates 74.125.92.25 as permitted sender) client-ip=74.125.92.25; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of wycats@gmail.com designates 74.125.92.25 as permitted sender) smtp.mail=wycats@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by qw-out-2122.google.com with SMTP id 3so1683176qwe.23 for ; Sun, 14 Jun 2009 08:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=bDvFAh+b48ODb35o0JyXZKdUxDrgshtDdld4i6Iraw8=; b=KP8yX9T2qaKrv7WAdiSjtLof7S958zEAqMtc5gig2C05gkTYGCCOBzuvouexOlRcxx cvr2N51bpQZydBdbxViivvdFf2ppKFeBzFXh1d2rYZEVZOqTcVY675e6eYgXp/WhYTNw BqTFoO1HbgAI/RFG1uCQXQRxVXa+QBgbxoMrc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=wwEAd6lf+xsYShAvScSiFw/g7TO7qwRk4K13/q88+fv+ckpikf0nHzZL9BrJhoEI+m x338f+Ro0HsH9ikvXDciY4NRtKEUfzKK7zqkAZfirUzCIgqNKFU2+1mFneDMSupt+4Mx rAqNf9N0a1GgEcSmcwFt9DZ29TJ33ycTStG2I= MIME-Version: 1.0 Received: by 10.224.67.75 with SMTP id q11mr6361807qai.226.1244993981089; Sun, 14 Jun 2009 08:39:41 -0700 (PDT) In-Reply-To: <299c839d0906140650n1849c528of36a6fee066a4a35@mail.gmail.com> References: <39345448-fc33-4712-8159-6da93fe9a189@h18g2000yqj.googlegroups.com> <299c839d0906140650n1849c528of36a6fee066a4a35@mail.gmail.com> From: Yehuda Katz Date: Sun, 14 Jun 2009 11:39:21 -0400 Message-ID: <245fb4700906140839h963cdc5k7c4c83d262931bf5@mail.gmail.com> Subject: Re: [PATCH] Request#accept_media_types To: rack-devel@googlegroups.com Content-Type: multipart/alternative; boundary=0015175d6720fd8673046c50bfb5 Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com --0015175d6720fd8673046c50bfb5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Take a look at what we do in Merb. We've optimized our Accept header parsing quite a bit (for performance; it can be shockingly slow), and handle quality factors (both absolute and relative). -- Yehuda On Sun, Jun 14, 2009 at 9:50 AM, Joshua Hull wrote: > > Just a couple of comments on this: > > types = types.select {|type| media_type_quality(type).between?(0.1, 1) } > > this should probably check that its greater than 0 and less than or > equal to 1 instead > > types = types.select {|type| quality = media_type_quality(type); > quality > 0 && quality <= 1 } > > so that values of 0.01 still get through. > > As well, the default value of all types is 1.0, but we probably want > to do something similar to what apache does, and assign */* a value of > 0.01 and type/* a value of 0.02. > > Cheers > Joshua > > On Fri, Jun 12, 2009 at 5:48 PM, mynyml wrote: > > > > Patch is at: > http://github.com/mynyml/rack/commit/c9953dbc3f834fdcbcd1ebc8b71b64eaf24d9e2b > > ----- > > Patch to add parsing of the HTTP_ACCEPT header's media types. Orders > > types by "quality" (preference level) (following HTTP 1.1 specs). > > > > The main advantage of being able to parse the Accept header is to > > centralize the lookup for the request's "desired" type(s). Usually, a > > client asks for a specific media type to be sent back by appending an > > extension to the URL; not only does this require parsing by every > > middleware/app that needs to know about this media type, but it also > > ignores the Accept hierarchy, which can be usefull for cascading down > > possible handlings of the resquest (think of a respond_to mechanism, > > for instance). > > > > I've encountered many use cases already: > > > > o > http://github.com/rack/rack-contrib/blob/3f42d3afe7323d322567d77cd404fb5bd8d9f1eb/lib/rack/contrib/accept_format.rb > > o http://github.com/mynyml/rack-abstract-format > > o http://github.com/mynyml/rack-supported-media-types > > o http://github.com/mynyml/rack-js4xhr > > o http://github.com/mynyml/rack-respond_to > > > > which led me to write the Accept header parsing code: > > > > o http://github.com/mynyml/rack-accept-media-types > > > > In my rack clone, the request_accept branch is a straight port of the > > rack-accept-media-types gem, and the request_accept-compact branch > > minimizes the code into two methods (instead of two classes). The > > latter reflects the rest of the Request class much better so it's > > probably a more appropriate patch. > > > > Feedback/questions/suggestions ? > > > > Thanks > -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 --0015175d6720fd8673046c50bfb5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Take a look at what we do in Merb. We've optimized our Accept header pa= rsing quite a bit (for performance; it can be shockingly slow), and handle = quality factors (both absolute and relative).

-- Yehuda

On Sun, Jun 14, 2009 at 9:50 AM, Joshua Hull <joshbuddy@gmail.com> wrote:

Just a couple of comments on this:

types =3D types.select {|type| media_type_quality(type).between?(0.1, 1) }<= br>
this should probably check that its greater than 0 and less than or
equal to 1 instead

types =3D types.select {|type| quality =3D media_type_quality(type);
quality > 0 && quality <=3D 1 }

so that values of 0.01 still get through.

As well, the default value of all types is 1.0, but we probably want
to do something similar to what apache does, and assign */* a value of
0.01 and type/* a value of 0.02.

Cheers
Joshua

On Fri, Jun 12, 2009 at 5:48 PM, mynyml<martin.aumont@gmail.com> wrote:
>
> Patch is at: http://github.com/mynyml= /rack/commit/c9953dbc3f834fdcbcd1ebc8b71b64eaf24d9e2b
> -----
> Patch to add parsing of the HTTP_ACCEPT header's media types. Orde= rs
> types by "quality" (preference level) (following HTTP 1.1 sp= ecs).
>
> The main advantage of being able to parse the Accept header is to
> centralize the lookup for the request's "desired" type(s= ). Usually, a
> client asks for a specific media type to be sent back by appending an<= br> > extension to the URL; not only does this require parsing by every
> middleware/app that needs to know about this media type, but it also > ignores the Accept hierarchy, which can be usefull for cascading down<= br> > possible handlings of the resquest (think of a respond_to mechanism, > for instance).
>
> I've encountered many use cases already:
>
> o http://github.com/rack/rack-contrib/blob/3f42d3afe7323d322567d77cd404fb5= bd8d9f1eb/lib/rack/contrib/accept_format.rb
> o http://github.com/mynyml/rack-abstract-format
> o http://github.com/mynyml/rack-supported-media-types
> o h= ttp://github.com/mynyml/rack-js4xhr
> o http://github.com/mynyml/rack-respond_to
>
> which led me to write the Accept header parsing code:
>
> o http://github.com/mynyml/rack-accept-media-types
>
> In my rack clone, the request_accept branch is a straight port of the<= br> > rack-accept-media-types gem, and the request_accept-compact branch
> minimizes the code into two methods (instead of two classes). The
> latter reflects the rest of the Request class much better so it's<= br> > probably a more appropriate patch.
>
> Feedback/questions/suggestions ?
>
> Thanks



--
Yehuda Katz=
Developer | Engine Yard
(ph) 718.877.1325
--0015175d6720fd8673046c50bfb5--