Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 46446 invoked from network); 21 Apr 2009 21:36:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Apr 2009 21:36:35 -0000 Received: (qmail 17370 invoked by uid 500); 21 Apr 2009 21:36:34 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 17293 invoked by uid 500); 21 Apr 2009 21:36:34 -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 17283 invoked by uid 99); 21 Apr 2009 21:36:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Apr 2009 21:36:34 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.200.172] (HELO wf-out-1314.google.com) (209.85.200.172) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Apr 2009 21:36:28 +0000 Received: by wf-out-1314.google.com with SMTP id 28so2912675wfa.29 for ; Tue, 21 Apr 2009 14:36:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.49.20 with SMTP id w20mr4883886wfw.328.1240349767457; Tue, 21 Apr 2009 14:36:07 -0700 (PDT) In-Reply-To: References: <1d3db2990904211228k1fcc29fie0f32ee280f05f02@mail.gmail.com> <1d3db2990904211251u1032b36en6527b772dc3901bd@mail.gmail.com> <1d3db2990904211356s3465b3ecx8f4cb07488074eac@mail.gmail.com> Date: Tue, 21 Apr 2009 14:36:07 -0700 Message-ID: <1d3db2990904211436w13b6e49fh17d3a613fee98326@mail.gmail.com> Subject: Re: specify Content-Type of a document? From: Samuel Wan 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 Ok, thanks for the confirmation. That was an interesting trip through the code. CouchDB is absolutely blowing my mind :-) -Sam On Tue, Apr 21, 2009 at 2:23 PM, Paul Davis w= rote: > On Tue, Apr 21, 2009 at 4:56 PM, Samuel Wan wrote: >> Thanks a lot for the pointer, Paul, it would have taken a long time to >> find otherwise. So lemme see if I got it right... >> >> The manual approach is to specify the content type as a member of the >> _show function's response object: >> >> - - - - - - - >> =A0return { >> =A0 =A0 =A0 =A0 =A0 "headers" : { >> =A0 =A0 =A0 =A0 =A0 =A0 "Content-Type" : "application/xml" >> =A0 =A0 =A0 =A0 =A0 }, >> =A0 =A0 =A0 =A0 =A0 "body" : new XML('') >> =A0 =A0 =A0 =A0 } >> - - - - - - - >> >> The convenient approach is to use some global variables and helper >> methods defined by CouchDB's /server/main.js file. One of >> these methods is registerType, which lets you register a type key with >> one or more MIME type strings. >> >> - - - - - - - >> registerType("foo", "application/foo", "application/x-foo"); //<-- >> stored to some global associative array defined by main.js >> - - - - - - - >> >> The other helper method is respondsWith, which accepts a second >> argument (a key-value object) that maps type keys to functions that >> return different kinds of HTTP responses depending on the type. >> > > That sounds pretty much right. I'll tell Chris to double check when he > gets back. > >> - - - - - - - >> return respondWith(req, { >> =A0 =A0 =A0 =A0 =A0html : function() { >> =A0 =A0 =A0 =A0 =A0 =A0return { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0body:"Ha ha, you said \"" + doc.word + "\"." >> =A0 =A0 =A0 =A0 =A0 =A0}; >> =A0 =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0 =A0foo : function() { >> =A0 =A0 =A0 =A0 =A0 =A0return { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0body: "foofoo" >> =A0 =A0 =A0 =A0 =A0 =A0}; >> =A0 =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0 =A0fallback : "html" >> =A0 =A0 =A0 =A0}); >> - - - - - - - >> >> So respondWith helper makes it easier for a show function respond to >> different Content-Type request headers... i think... Since there's a >> test for it, I guess content-type handling in the server-side JS is >> something CouchDB intends to support moving forward... >> > > Yep, they're features that CouchDB is comitted to keeping. > > > Paul Davis > >> -Sam >> >> >> On Tue, Apr 21, 2009 at 12:57 PM, Paul Davis >> wrote: >>> Sam, >>> >>> This sounds very much like you want a _show function. Both _show and >>> _list can specify the content-type returned to the client. You'll want >>> to check the test suite code and look for the respondWith stuff for >>> examples. >>> >>> HTH, >>> Paul Davis >>> >>> On Tue, Apr 21, 2009 at 3:51 PM, Samuel Wan wrote: >>>> I'm trying to build a simple learning experiment where I can write >>>> HTML and Javascript into documents, and retrieve them with a GET >>>> request. However, I don't know how to specify text/html or >>>> application/x-javascript as the Content-Type headers in the response >>>> to a document request. >>>> >>>> Is the recommended practice to simply store the html or js text as >>>> attachments, or is it possible somehow to use a "show" function to >>>> send them back with specific content type headers? I read some of >>>> Chris Anderson's posts, the Safari Rough Cuts book, and looked a bit >>>> at the CouchApp code, but it might be too much to grasp all at once >>>> for me. >>>> >>>> -Sam >>>> >>>> On Tue, Apr 21, 2009 at 12:33 PM, Paul Davis >>>> wrote: >>>>> Sam, >>>>> >>>>> We're consistently inconsistent in that we only sometimes check for >>>>> the content-type when posting JSON documents. Of the top of my head I >>>>> know we check in _temp_views but not for PUTs and POSTs to docs or >>>>> _bulk_docs. >>>>> >>>>> If you mean for adding attachments to docs though CouchDB will just >>>>> send you back the content-type header you attached it with so you can >>>>> control what clients will see when fetching attachments. >>>>> >>>>> HTH, >>>>> Paul Davis >>>>> >>>>> On Tue, Apr 21, 2009 at 3:28 PM, Samuel Wan wrote= : >>>>>> Is it possible to specify the Content-Type header of a document? Do >>>>>> you need to use a "show" function? >>>>>> >>>>>> -Sam >>>>>> >>>>> >>>> >>> >> >