Hi~

On Sep 11, 2007, at 8:35 AM, ry dahl wrote:

> It's because Merb doesn't write status or headers on procs. Presumably
> because Merb doesn't yet know the Content-Length of the response?
>
> I'm all for changing this: returning headers and status (without
> Content-Length) on proc return values before calling the proc.
>
> ry
>
> On 9/11/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> I'm just playing with a recent Merb trunk (-r590). All the specs  
>> pass, apart
>> from 2 pending.
>>
>> Now, the README says: "if you return a Proc object from your  
>> action, it will
>> be called and the return value sent to the client."
>>
>> However this doesn't seem to work with the following test controller:
>>
>> class Hello < Application
>>  def world
>>    res = "Hello world from #{$$} at #{Time.now}!\n"
>>    proc {
>>      sleep 5
>>      res
>>    }
>>  end
>> end
>>
>> I get the 5 second wait, but zero bytes of response.
>>
>> $ telnet localhost 4000
>> Trying 127.0.0.1...
>> Connected to localhost.localdomain (127.0.0.1).
>> Escape character is '^]'.
>> GET /hello/world HTTP/1.0
>>
>> HTTP/1.1 200 OK
>> Connection: close
>> Date: Tue, 11 Sep 2007 12:43:51 GMT
>> Content-Type: text/html
>> Content-Length: 0
>>
>> Connection closed by foreign host.
>>
>> It works if I remove the proc { ... } wrapper and just return the  
>> string
>> directly.
>>
>> I'm pretty sure I'm doing the proc return correctly; if I write it  
>> as a
>> standalone Ruby program then it behaves as I expect, i.e.
>>
>> def world
>>  res = "Hello world from #{$$} at #{Time.now}!\n"
>>  proc {
>>    sleep 5
>>    res
>>  }
>> end
>> puts world.call   # this works and shows the message
>>
>> Anybody got any idea why this doesn't work? I'm not submitting  
>> this as a

>> ticket as I'm not sure if the behaviour is wrong, the README is  
>> wrong, or
>> I'm doing something wrong :-)
>>
>> Thanks,
>>
>> Brian.


Brian-

        There is a helper method for this that sets all the proper headers  
and whatnot. Here is how to use it to do what your example does:

def world
   res = "Hello world from #{$$} at #{Time.now}!\n"
   render_defered do
     sleep 5
     res
   end
end

Cheers-

-- Ezra Zygmuntowicz 
-- Founder & Ruby Hacker
-- [EMAIL PROTECTED]
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)


_______________________________________________
Merb-devel mailing list
Merb-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/merb-devel

Reply via email to