From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.204.72.79 with SMTP id l15cs164781bkj; Mon, 15 Jun 2009 12:58:50 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.100.91.18 as permitted sender) client-ip=10.100.91.18; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.100.91.18 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.100.91.18]) by 10.100.91.18 with SMTP id o18mr2487969anb.29.1245095929846 (num_hops = 1); Mon, 15 Jun 2009 12:58:49 -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:date:message-id:subject:from:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=aHmm0CFh6ojipDLlIZGX5Nvp3m9J4rH9OKft1zrDNV0=; b=0GEfzNUC0FGdHLtTLaC+vNJs9M0jx83MbkY4XSWi73WSJdrMdCuGYtxTzQWq4RqPYB cYN/If9I4Ew7miOfnIeUH1c6sR2t+4VIOjwb8/c9HI29T8w/aUJ95tSMqmVXaNMSCfzN rSHlAnCwpRxUz1IKKB8aDr6Vx90UushqPDiuc= 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:date:message-id:subject:from:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; b=a0ilZvQumjezfVFeSrKjwwiNL+Msoba8fagN4hIqlfzdd4cUht1U2aJl7AzVIC3MPW YMW2S4gL01ukzP04xQAZR4EoDvfvDw44i3R/nsd6RyQNCmPoFviOvQUxYcLRezB6Dh5F 1V0fdwpnoFJLKvQDboWGVzkdH9k+Wii/aVNIY= Received: by 10.100.91.18 with SMTP id o18mr387684anb.29.1245095929659; Mon, 15 Jun 2009 12:58:49 -0700 (PDT) Received: by 10.106.129.7 with SMTP id b7gr1451prd.0; Mon, 15 Jun 2009 12:58:49 -0700 (PDT) X-Sender: rtomayko@gmail.com X-Apparently-To: rack-devel@googlegroups.com Received: by 10.224.19.136 with SMTP id a8mr1526380qab.12.1245095928826; Mon, 15 Jun 2009 12:58:48 -0700 (PDT) Return-Path: Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.26]) by gmr-mx.google.com with ESMTP id 21si413532qyk.2.2009.06.15.12.58.47; Mon, 15 Jun 2009 12:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of rtomayko@gmail.com designates 74.125.92.26 as permitted sender) client-ip=74.125.92.26; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of rtomayko@gmail.com designates 74.125.92.26 as permitted sender) smtp.mail=rtomayko@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by qw-out-2122.google.com with SMTP id 9so1928314qwb.47 for ; Mon, 15 Jun 2009 12:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=guxTkUiNAXvQuirpZ+xtcoP7SCyD9HTHZEeeGd3tb4I=; b=ePOZ9zCyEoyGd3m7SqBDEyPpAy5oTZ/T0W3KF4DLvq2ixxWqAkNB7BCXjA1aaNwehC /39Y8iv2CgsREGFL/To4241bg64T7SW4pThUQ7qqxVOvoPLxyX5jd0CWayYfL9Pd+7QG SH9pZKmZyqxarFEiHqzkcUG2KFYKaIBY0/AyQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=Su3W08o+O/rs6yhEuLkTKlJ5LKAptXwMrBFeHWvvxJzn25M1gEcUl6BUrNNJ0K5eAl f/lZNeKlgkHgtS5pF/90B3jgVeT26xWSkelASU+dZE6vF3s/8RDNZDNvXRZBeVQGPFRA RAdjzy+UoU/kd2N+Gd4Fza7PwE5YcTKHtF+DE= MIME-Version: 1.0 Received: by 10.224.37.66 with SMTP id w2mr7641639qad.310.1245095927026; Mon, 15 Jun 2009 12:58:47 -0700 (PDT) In-Reply-To: <245fb4700906140839h963cdc5k7c4c83d262931bf5@mail.gmail.com> References: <39345448-fc33-4712-8159-6da93fe9a189@h18g2000yqj.googlegroups.com> <299c839d0906140650n1849c528of36a6fee066a4a35@mail.gmail.com> <245fb4700906140839h963cdc5k7c4c83d262931bf5@mail.gmail.com> Date: Mon, 15 Jun 2009 12:58:47 -0700 Message-ID: Subject: Re: [PATCH] Request#accept_media_types From: Ryan Tomayko To: rack-devel@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 I haven't reviewed the patch yet but I'd love to have a set of simple utility classes/methods/mixins for parsing basic HTTP header value types. Accept, Accept-Language, Accept-Encoding, Cache-Control, etc. all follow a few simple syntax grammars. We could then use the utilities from Rack::Request, or directly from framework/app code if more control is needed. Ryan On Sun, Jun 14, 2009 at 8:39 AM, Yehuda Katz wrote: > 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 >