rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Ryan Tomayko <r@tomayko.com>
To: rack-devel@googlegroups.com
Subject: Re: [PATCH] Request#accept_media_types
Date: Mon, 15 Jun 2009 12:58:47 -0700	[thread overview]
Message-ID: <f732822d0906151258j4390255dp4dd2c3cacf72450a@mail.gmail.com> (raw)
In-Reply-To: <245fb4700906140839h963cdc5k7c4c83d262931bf5@mail.gmail.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<wycats@gmail.com> 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 <joshbuddy@gmail.com> 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<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. 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
>

  reply	other threads:[~2009-06-15 19:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-12 21:48 [PATCH] Request#accept_media_types mynyml
2009-06-14 13:50 ` Joshua Hull
2009-06-14 15:39   ` Yehuda Katz
2009-06-15 19:58     ` Ryan Tomayko [this message]
2009-06-15 21:03       ` Request#accept_media_types mynyml
2009-06-19 15:55         ` Request#accept_media_types mynyml

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f732822d0906151258j4390255dp4dd2c3cacf72450a@mail.gmail.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).