couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benoit Chesneau (JIRA)" <>
Subject [jira] Updated: (COUCHDB-591) _rewrite handler
Date Fri, 29 Jan 2010 06:33:34 GMT


Benoit Chesneau updated COUCHDB-591:

    Attachment: couch_httpd_rewriter2.diff

This new patch is a complete rewrite. Now rewriting is fully handled in Erlang :

The rewriting root is the
the design doc :


ddocname should contain a "rewrites" member which a list of rewriting
rules. If not it will return a 404.

ex :
       "rewrite": [
               "from": "",
               "to": "index.html",
               "method": "GET",
               "query": {}

Urls are relative to ddoc :
give same results: /somedb/ddoc/_design/_show/test/...

However it's also possible  to do :
    ../../_changes -> /somedb/_changes
and :
     ../../../somedb -> /somedb
or :
    ../../../_utils -> _utils

Rewriting can use variables. Variables in path are prefixed by ":".
For example the following rule:

    { "from": "show/:id", "to": "_show/mydoc/:id" }

will rewrite  "/mydb/_design/test/_rewrite/show/someid" to "/mydb/_design/test/_show/someid".

    { "from": "view/:type", "to": "_list/types/by_types", query: {
"key": "type" }

will rewrite  "/mydb/_design/test/_rewrite/view/sometype" to

"*" is a special variable and should be the last. It means "all remaining in path". Ex if
for from we have  /test/*, *, * Will mean "someurl" in /test/url . "*" could be used in the
rewritten url or query too. Ex:

{ "from": "show/*", "to": "_show/mydoc/* }

will rewrite  "/mydb/_design/test/_rewrite/show/someid" to "/mydb/_design/test/_show/someid".


> _rewrite handler
> ----------------
>                 Key: COUCHDB-591
>                 URL:
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>    Affects Versions: 0.11
>            Reporter: Benoit Chesneau
>         Attachments: couch_httpd_rewriter2.diff, couchdb_rewrite.patch
> Find attached a patch providing simple url rewritig in CouchDB. You can also find it
in my github repo :
> The design is very simple. Everything is managed via a simple javascript function that
return a path or throw 'forbidden', 'unauthorized' and "not found" errors. The request object
is passed to the function and then depending on the path, verb or userCtx you could decide
how to rewrite the path. All relatives path are relative to design doc.
> The _rewriter is available at db or _design level :
> /db/_rewrite/designname/path
> or
> /db/_design/designame/_rewrite/path.
> Then _rewrite handler look in design doc if `rewrite` member exists and load the function.
 A snippet is avalaible here :

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message