Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 4034 invoked from network); 15 Apr 2010 17:57:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 17:57:32 -0000 Received: (qmail 38960 invoked by uid 500); 15 Apr 2010 17:57:31 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 38787 invoked by uid 500); 15 Apr 2010 17:57:31 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 38779 invoked by uid 99); 15 Apr 2010 17:57:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 17:57:31 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of 7zark7@gmail.com designates 74.125.83.180 as permitted sender) Received: from [74.125.83.180] (HELO mail-pv0-f180.google.com) (74.125.83.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 17:57:24 +0000 Received: by pvc22 with SMTP id 22so1049313pvc.11 for ; Thu, 15 Apr 2010 10:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:content-type :content-transfer-encoding; bh=L3i2qm+PscpB3OVcPoZ5Nj6o8PrnZr0g3zg7wUT2Dbg=; b=Ee3JpQ2yxd4qmfNQ7gLBUTR38ErH/uechrCI38oU86N3l4QMLO3lTsycUjh6lEkwL8 BWMxqmqdBnQu3npwLw14Nixefr6gjw9b02aDKXqNhyQiu46Cm0Hn9puMNxEcRfd6LVHu iEu/zS5ldSOVuibilwO59ZlY5z/nW0P7h+2Fo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=mwUtgT52uNK8N/zgILHNkqmaFJhaOu5IwgiYGknOs0OSRBGEc63+GFoySX8YqHGWmH ZgAVbdOB0kqSGqr/dFDHhhzL3hxmplgUPY2HHYCfL2tRhIJfUeYFM24eJAqBZACSpcSU DEKQXQ80DiaQ3Jgq3GllxK3vsJkTcHOLmT/zc= MIME-Version: 1.0 Received: by 10.142.158.12 with HTTP; Thu, 15 Apr 2010 10:57:02 -0700 (PDT) In-Reply-To: <2C77A5E5-FC0D-45CA-82DB-F8CCD1E17E75@gmail.com> References: <2C77A5E5-FC0D-45CA-82DB-F8CCD1E17E75@gmail.com> Date: Thu, 15 Apr 2010 10:57:02 -0700 Received: by 10.142.196.10 with SMTP id t10mr363786wff.223.1271354222630; Thu, 15 Apr 2010 10:57:02 -0700 (PDT) Message-ID: Subject: Re: List functions and headers using send, getRow From: Anh <7zark7@gmail.com> To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Thu, Apr 15, 2010 at 9:48 AM, J Chris Anderson wrote: > > On Apr 15, 2010, at 8:22 AM, Zachary Zolton wrote: > >> You can use the provides() helper function in your list _functions: >> >> function(head, req) { >> =A0provides('html', function() { >> =A0 =A0send('
    '); >> =A0 =A0var row; >> =A0 =A0while (row =3D getRow()) { >> =A0 =A0 =A0 =A0send('
  • ' + row.id + '
  • '); >> =A0 =A0} >> =A0 =A0return '
'; >> =A0}); >> } >> >> The fun part is that you can use provides() multiple times to make the >> same _list function handle multiple content types (i.e. html, xml, >> atom) that result from requesting the URL with different Accept >> headers. >> > > Since most browsers are lousy at Accept headers you can also do query par= ams like: > > /db/_design/foo/_list/bam?format=3Dxml > > which provides will handle in an unsurprising way. > > Thank you, works very nicely - I was thrown off by the examples using "return {...}" versus send(). BTW, are there any online docs which allow you to click on various functions and which contexts they are available? I'm a Java guy, so thinking along the lines of online Javadocs, etc. Thanks again >> On Thu, Apr 15, 2010 at 3:17 AM, Anh <7zark7@gmail.com> wrote: >>> Hi, >>> >>> I'm a little confused on how to set the content-type header for list >>> functions which return HTML. >>> I'm using the send() and getRow() functions: >>> >>> function(head, req) { >>> =A0 =A0send('
    '); >>> =A0 =A0var row; >>> =A0 =A0while (row =3D getRow()) { >>> =A0 =A0 =A0 =A0send('
  • ' + row.id + '
  • '); >>> =A0 =A0} >>> =A0 =A0send('
'); >>> } >>> >>> which works fine, but I'm not setting any content-type headers. >>> >>> The examples I see in the docs use return, which returns the entire >>> body as well: >>> >>> return { >>> =A0 "headers" : {"Content-Type" : "application/xml"}, >>> =A0 "body" : new XML('') >>> } >>> >>> >>> Do I have to build the whole body as a string first, and then return it= ? >>> >>> If so, that would seems to lose a benefit of list functions, that you >>> can process and send each row at a time, versus eating memory. >>> >>> >>> Thanks, any help would be appreciated. >>> > >