<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>examples/async.js</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,6 +3,12 @@ var HashP = require(&quot;hashp&quot;).HashP;
 var Response = exports.Response = function(status, headers, body) {
     var that = this;
     
+    if (typeof arguments[0] === &quot;object&quot;) {
+        headers = arguments[0].headers;
+        body = arguments[0].body;
+        status = arguments[0].status;
+    }
+    
     this.status = status || 200;
     this.headers = HashP.merge({&quot;Content-Type&quot; : &quot;text/html&quot;}, headers);
     
@@ -64,7 +70,8 @@ Response.prototype.setCookie = function(key, value) {
     }
 
     if (Array.isArray(value)) {
-        for (var i in value) cookie += encodeURIComponent(value[i]);
+        for (var i = 0; i &lt; value.length; i++)
+            cookie += encodeURIComponent(value[i]);
     } else {
         cookie += encodeURIComponent(value);
     }
@@ -138,12 +145,51 @@ Response.prototype.isEmpty = function() {
 
 Response.redirect = function(location, status) {
     status = status || 303;
+    var body = 'Go to &lt;a href=&quot;' + location + '&quot;&gt;' + location + '&lt;/a&gt;';
     return {
         status : status,
         headers : {
             &quot;Location&quot;: location,
-            &quot;Content-type&quot;: &quot;text/plain&quot;
+            &quot;Content-Type&quot;: &quot;text/plain&quot;,
+            &quot;Content-Length&quot;: String(body)
         },
-        body : ['Go to &lt;a href=&quot;' + location + '&quot;&gt;' + location + &quot;&lt;/a&gt;&quot;]
+        body : [body]
     };
 }
+
+var AsyncResponse = exports.AsyncResponse = function(status, headers, body) {
+    // set the buffer up first, since Response's constructor calls .write()
+    this._buffer = [];
+    
+    this._callback  = null;
+    this._errback   = null;
+    
+    Response.apply(this, arguments);
+    
+    this.body = { forEach : this.forEach.bind(this) };
+}
+
+AsyncResponse.prototype = Object.create(Response.prototype);
+
+// this &quot;write&quot; gets overriden later by the callback provided to forEach
+AsyncResponse.prototype.write = function(chunk) {
+    this._buffer.push(chunk);
+}
+
+AsyncResponse.prototype.forEach = function(callback) {
+    this._buffer.forEach(callback);
+    this._buffer = null;
+    
+    this.write = callback;
+
+    return { then : this.then.bind(this) };
+}
+
+AsyncResponse.prototype.then = function(callback, errback) {
+    this._callback = callback;
+    this._errback = errback;
+}
+
+AsyncResponse.prototype.close = function() {
+    this._callback();
+}</diff>
      <filename>lib/jack/response.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ef5fdafc989657c308def2d015cc32e234b071f8</id>
    </parent>
  </parents>
  <author>
    <name>Tom Robinson</name>
    <email>tom@280north.com</email>
  </author>
  <url>http://github.com/gmosx/jack/commit/3ee7b56812c97770318891a0fd21287cae9ccfc2</url>
  <id>3ee7b56812c97770318891a0fd21287cae9ccfc2</id>
  <committed-date>2009-10-09T04:04:51-07:00</committed-date>
  <authored-date>2009-10-09T04:04:51-07:00</authored-date>
  <message>Added an AsyncResponse object and example.</message>
  <tree>e60efeda7e4a7dcd297fc23ea072cbd654a942f5</tree>
  <committer>
    <name>Tom Robinson</name>
    <email>tom@280north.com</email>
  </committer>
</commit>
