rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: mynyml <martin.aumont@gmail.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Re: Request#accept_media_types
Date: Fri, 19 Jun 2009 08:55:42 -0700 (PDT)	[thread overview]
Message-ID: <a0cfb622-4da6-4b1f-9a23-9e1f3cc092fa@r34g2000vba.googlegroups.com> (raw)
In-Reply-To: <51b72270-d718-417a-aa65-d1db71c1dd31@g15g2000pra.googlegroups.com>


Did anyone get a chance to take a look at the updated patch? Any more
suggestions?

Thanks


On Jun 15, 5:03 pm, mynyml <martin.aum...@gmail.com> wrote:
> @Joshua: Nice catch about the quality values. The specs do specify
> they can contain up to three decimal digits. I updated the code to
> reflect that.
>
> Now about Apache's behaviour of assigning 0.01 to */* and 0.02 to type/
> *: I didn't know about this so I did some reading. Seems that Apache
> does that as a fix for browsers that don't send any quality values at
> all, as it assumes they don't really know what they're doing.
>
>  http://httpd.apache.org/docs/1.3/content-negotiation.html#better
>
> Turns out though there is another part of the HTTP spec (that I had
> previously missed), which is that more specific types override less
> specific ones. This automatically takes care of apache's behaviour. I
> updated the code to include this too.
>
> @Ryan: The code was becoming too repetitive so I split the media type
> handling into it's own class. I put it in Rack::Mime::MimeType. I
> guess that could provide a starting point. It could eventually
> subclass something more generic.
>
> @Yehuda: TBH I don't think I know enough performance optimization
> tricks to add significant improvements, but I added the basics by
> caching the parsed output.
>
> Latest patch is @
>  http://github.com/mynyml/rack/commit/2f0a743fe3a55b07cf0fc75ba06cb318...
>
> Questions, suggestions, patches?
> Anyone wants to tackle performance? =)
>
> On Jun 15, 3:58 pm, Ryan Tomayko <r...@tomayko.com> wrote:
>
> > 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<wyc...@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 <joshbu...@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.aum...@gmail.com> wrote:
>
> > >> > Patch is at:
> > >> >http://github.com/mynyml/rack/commit/c9953dbc3f834fdcbcd1ebc8b71b64ea...
> > >> > -----
> > >> > 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/3f42d3afe7323d322567d77cd404...
> > >> > ohttp://github.com/mynyml/rack-abstract-format
> > >> > ohttp://github.com/mynyml/rack-supported-media-types
> > >> > ohttp://github.com/mynyml/rack-js4xhr
> > >> > ohttp://github.com/mynyml/rack-respond_to
>
> > >> > which led me to write the Accept header parsing code:
>
> > >> > ohttp://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-19 15:57 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
2009-06-15 21:03       ` Request#accept_media_types mynyml
2009-06-19 15:55         ` mynyml [this message]

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=a0cfb622-4da6-4b1f-9a23-9e1f3cc092fa@r34g2000vba.googlegroups.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).