couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Chris Anderson <>
Subject Re: Content-Type Negotiation/Programmatic URL rewriting
Date Thu, 11 Mar 2010 05:07:42 GMT

On Mar 10, 2010, at 7:47 PM, Robert Newson wrote:

> All,
> I want to retrieve the JSON document or a specific binary attachment
> of it from the same URL, conditional on the Accept header. That is,
> "/db/doc" is either JSON metadata or a binary stream, depending on
> content-type negotiation. The below rewrite enhancement would achieve
> it, I think, but perhaps there's a cleaner way? Right now, I'm adding
> another Erlang module to achieve this but I would really like to do it
> entirely from a design document.
> I'm thinking of writing a new kind of rewrite handler. I have a case
> where it would be very useful to rewrite a URL based on the contents
> of a request header. That is, the presence of a particular header will
> alter the path, but not otherwise;
> {
>   "_id":"_design/foo",
>  "rewrites": {
>    "bar": {
>      "function":"function(req){ if (req.headers["Accept"] == blah) {
> return req.path + "extra";} return req.path"
> that is, the rewrite handler would get a full request object and
> return the rewritten path, and could use anything from the request to
> do so.

we originally decided against an executable rewrite handler for reasons of performance.

is there a way to add to the pattern matching api to achieve this?


> Thoughts?
> B.

View raw message