Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 87716 invoked from network); 17 Dec 2010 18:26:07 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Dec 2010 18:26:07 -0000 Received: (qmail 34141 invoked by uid 500); 17 Dec 2010 18:26:06 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 34089 invoked by uid 500); 17 Dec 2010 18:26:06 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 34076 invoked by uid 99); 17 Dec 2010 18:26:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Dec 2010 18:26:06 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of volker.mische@gmail.com designates 209.85.161.54 as permitted sender) Received: from [209.85.161.54] (HELO mail-fx0-f54.google.com) (209.85.161.54) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Dec 2010 18:25:58 +0000 Received: by fxm16 with SMTP id 16so950771fxm.27 for ; Fri, 17 Dec 2010 10:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=TKXWH+GgoOS6JqsSwuehIz9a99kLOePEYH9Zr8GDujc=; b=hPwT+XL7B657mlbzoqJXWptL7hEukS5zkKAGpO9D1dvGrGpo0d3Fp8wXrmFG+0pQrz GPF4jr8ef1tR5LEUtLD3S9aifhNDrr/NLyhTd2v4hYHvkOGOD+xQ8JJVoU1I99uR/3Ne vc5Oh1IC5SiZCy2Y6J0zphFJJf0g+HOHGXWds= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=bV78dRGe5ttwROyFlxxSmjpLGJLnks0j5jsZks5eVao9K4Vae+LXdEifi68gEfE93I S3B82NGLjXLOtLcgofxjr/7M2ZTT2cIHtPSo/SDRiA/teMxHbjF9t3A0O+tn9Be3SYqs th31s9dtQz1vicaNkPnZjnKvA61q8JLL5QWmw= Received: by 10.223.103.3 with SMTP id i3mr1396071fao.137.1292610338283; Fri, 17 Dec 2010 10:25:38 -0800 (PST) Received: from [192.168.0.3] (dslb-084-056-011-169.pools.arcor-ip.net [84.56.11.169]) by mx.google.com with ESMTPS id y14sm184012fak.42.2010.12.17.10.25.36 (version=SSLv3 cipher=RC4-MD5); Fri, 17 Dec 2010 10:25:36 -0800 (PST) Message-ID: <4D0BAB18.6010204@gmail.com> Date: Fri, 17 Dec 2010 19:25:28 +0100 From: Volker Mische User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100922 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: dev@couchdb.apache.org Subject: Rewriter: ability to replace substrings Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi devs, I wanted to rewrite URL beyond that what's currently possible with the CouchDB rewrite. I especially had in mind URLs where that need to conform to a certain standard and where you need a proxy in front of it to serve them up in that specific way. I have two use cases in mind. First one with for wikis with subpages. You might want to have URLs like: http://example.com/wiki/apache-projects/couchdb/info as opposed to http://example.com/wiki/apache-projects%2fcouchd%2f/info While I tried this with JChris' Pages wiki, I found out that if a _show function is used, you can also have such URLs with the current rewriter (though directly accessing the documents with non URL encoded slashes won't be possible). My second one is a TMS tilecache [1]. Those who don't know what it is, it's for serving up map tiles like Google or OpenStreetmap does. I would create a document per tile and attach the file to it. My URL would look like this (where "tile" is the attachement): http://example.com/tilecache/3-5-2/tile But I'd need an URL like http://example.com/tilecache/tiles/3/5/2.png (resp. http://example.com/tilecache/_design/tilecache/_rewrite/tiles/6/9/9.png) My modification to the rewriter allows you to replace substrings with other ones. Here's the rewriter rule for this example: { "from" : "/tiles///.png", "to" : "..\\/..\\/:x/:y/:z/tile", "replace": { "old": "/", "new": "-", "limit": -1 } } It replaces all occurences of "/" with "-" on the "to"-path. Two slashes ("\\") escape a character, so it won't be replaced. The "limit" parameter specifies how many occurences should be replaced. It could be either positive, then it will just count how often a string was already replaced and stop at the limit. If "limit" is negative, it will count from the back. This is especially useful if you want to replace slashes and know how many slashes the attachment has, but not how many the document has. The changes are available here: https://github.com/vmx/couchdb/commit/889024df75892fb46a1e513e54466fa5bbe69e49 Comments please :) [1] http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification Cheers, Volker