couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <>
Subject Content-Type Negotiation/Programmatic URL rewriting
Date Thu, 11 Mar 2010 03:47:07 GMT

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;

  "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.


View raw message