<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -75,7 +75,7 @@ class SimpleApp
     end
     
     body += &quot;\r\n&quot;
-    headers = {'Content-Type' =&gt; 'text/plain', 'Content-Length' =&gt; body.length.to_s }
+    headers = {'Content-Type' =&gt; 'text/plain', 'Transfer-Encoding' =&gt; &quot;chunked&quot; }
     [status, headers, [body]]
   end
 end</diff>
      <filename>application.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,12 +38,8 @@ module Flow
 
     def initialize(socket, app)
       @app = app
-
       @timeout = Timeout.new(self, TIMEOUT) 
-
       @parser = Ebb::RequestParser.new(self)
-
-      @requests = []
       @responses = []
       super(socket)
     end
@@ -73,7 +69,6 @@ module Flow
     end
 
     def process(req)
-      @requests &lt;&lt; req
       res = req.response
       status, headers, body = @app.call(req.env)
 
@@ -81,6 +76,9 @@ module Flow
       # check out
       # http://github.com/raggi/thin/tree/async_for_rack/example/async_app.ru
       res.call(status, headers, body) if status != 0 
+      # if status == 0 then the application promises to call
+      # env['async.callback'].call(status, headers, body) 
+      # later on...
 
       @responses &lt;&lt; res
       write_response
@@ -88,21 +86,20 @@ module Flow
 
     def write_response
       return unless res = @responses.first
-      if res.finished?
-        @responses.shift
-        if res.last
-          close
-        else
-          write_response
-        end
-      else 
-        while chunk = res.output.shift
-          write(chunk)
-        end
+      while chunk = res.output.shift
+        write(chunk)
       end
     end
 
     def on_write_complete
+      return unless res = @responses.first
+      if res.finished
+        @responses.shift
+        if res.last 
+          close 
+          return
+        end
+      end 
       write_response
     end
 
@@ -136,30 +133,39 @@ module Flow
       @chunked = false 
     end
 
-    def finished?
-      @finished 
-    end
-
     def call(status, headers, body)
-      head = &quot;HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status.to_i]}\r\n&quot;
-      headers.each { |field, value| head &lt;&lt; &quot;#{field}: #{value}\r\n&quot; }
-      head &lt;&lt; &quot;\r\n&quot;
-      @output &lt;&lt; head
+      @output &lt;&lt; &quot;HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status.to_i]}\r\n&quot;
+      headers.each { |field, value| @output &lt;&lt; &quot;#{field}: #{value}\r\n&quot; }
+      @output &lt;&lt; &quot;\r\n&quot;
 
       # XXX i would prefer to do
       # @chunked = true unless body.respond_to?(:length)
-      @chunked = true if headers[&quot;Content-Encoding&quot;] == &quot;chunked&quot;
+      @chunked = true if headers[&quot;Transfer-Encoding&quot;] == &quot;chunked&quot;
+      # I also don't like this
+      @last = true if headers[&quot;Connection&quot;] == &quot;close&quot;
+
+      # Note: not setting Content-Length. do it yourself.
+      
+      ## XXX Have to do this so it is known when end is recieved!
+      if body.kind_of?(Array) and body.last != nil
+        body.push(nil)
+      end
 
       body.each do |chunk|
-        @output &lt;&lt; encode(chunk)
-        @finished = true if chunk.nil?
+        if chunk.nil? or 
+           (body.respond_to?(:eof?) and body.eof?) ## XXX annoying. need to know end.
+        then
+          @finished = true 
+          @output &lt;&lt; &quot;0\r\n\r\n&quot; if @chunked
+        else
+          @output &lt;&lt; encode(chunk)
+        end
         @connection.write_response
       end
     end
     
     def encode(chunk)
-      c = chunk || &quot;&quot; # encodes a nil chunk too
-      @chunked ?  &quot;#{c.length.to_s(16)}\r\n#{c}\r\n&quot; : c
+      @chunked ? &quot;#{chunk.length.to_s(16)}\r\n#{chunk}\r\n&quot; : chunk
     end
 
     HTTP_STATUS_CODES = {
@@ -233,7 +239,7 @@ module Ebb
 
       def response
         @response ||= begin
-          last = !keep_alive?
+          last = !keep_alive? # this is the last response if the request isnt keep-alive
           Flow::Response.new(@connection, last)
         end
       end</diff>
      <filename>lib/flow.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d5641d2cdae4d0e9537d5203a8610a02252c8320</id>
    </parent>
  </parents>
  <author>
    <name>Ryan</name>
    <email>ry@tinyclouds.org</email>
  </author>
  <url>http://github.com/ry/flow/commit/fec84c45fba4ff8a6d03aa3c601fea6986d5f29a</url>
  <id>fec84c45fba4ff8a6d03aa3c601fea6986d5f29a</id>
  <committed-date>2008-08-07T08:50:49-07:00</committed-date>
  <authored-date>2008-08-07T08:50:49-07:00</authored-date>
  <message>small fixes to get chunked encoding working</message>
  <tree>71b7c44da3067748ac86557baf1780e5c9ac6445</tree>
  <committer>
    <name>Ryan</name>
    <email>ry@tinyclouds.org</email>
  </committer>
</commit>
