From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.140.141.15 with SMTP id o15cs63929rvd; Wed, 3 Feb 2010 10:08:41 -0800 (PST) Received-SPF: pass (google.com: domain of 3p7tpSwYPChg72F2AM56B24yF1B2F.CF4Fy08-12J294CC4924FCIDG.0CA@groups.bounces.google.com designates 10.101.165.34 as permitted sender) client-ip=10.101.165.34; Authentication-Results: mr.google.com; spf=pass (google.com: domain of 3p7tpSwYPChg72F2AM56B24yF1B2F.CF4Fy08-12J294CC4924FCIDG.0CA@groups.bounces.google.com designates 10.101.165.34 as permitted sender) smtp.mail=3p7tpSwYPChg72F2AM56B24yF1B2F.CF4Fy08-12J294CC4924FCIDG.0CA@groups.bounces.google.com; dkim=pass header.i=3p7tpSwYPChg72F2AM56B24yF1B2F.CF4Fy08-12J294CC4924FCIDG.0CA@groups.bounces.google.com Received: from mr.google.com ([10.101.165.34]) by 10.101.165.34 with SMTP id s34mr9756906ano.58.1265220520683 (num_hops = 1); Wed, 03 Feb 2010 10:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:date:from:to:subject:message-id :reply-to:mail-followup-to:references:mime-version:in-reply-to :user-agent:x-original-authentication-results:x-original-sender :precedence:mailing-list:list-id:list-post:list-help:list-archive :x-thread-url:x-message-url:sender:list-subscribe:list-unsubscribe :content-type:content-disposition; bh=1YhILCrT2CcFoRRw76NjotfNdw5WBNZaISb1VZsdDVA=; b=G4QibTf9SX62JKvt4LVsBcrWLDk7c8Phlt2Yluuxj17VSYFTyDeW4fWaYbfSgBZxZD mKC78AqehTsp4ddhf5Oc7QsC3CH80JcX7FvSbefEC4xFgzS0nThmRoIPDZ532xN3ZK6V yiDpl2SrFtuNx1Gap0mca45Q6sWkeIyXze/74= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:date:from:to:subject:message-id:reply-to :mail-followup-to:references:mime-version:in-reply-to:user-agent :x-original-authentication-results:x-original-sender:precedence :mailing-list:list-id:list-post:list-help:list-archive:x-thread-url :x-message-url:sender:list-subscribe:list-unsubscribe:content-type :content-disposition; b=MfxZb1+1GqPXUW7V17+OhC+SAJYC4I9gDDeuUi79Jf0f2agib/Zr6DCrs+2rPnRXSV iS0KA5pMR3vdXucfLLwuhyaXD12bxj7A1yXHKPIXVGsop0d+1swDsqZv6TNqTQVNgLWM e2sw7Vd6rQZRC3n3iAhvWgtnSoa69w2wam1Cs= Received: by 10.101.165.34 with SMTP id s34mr548571ano.58.1265220519446; Wed, 03 Feb 2010 10:08:39 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.231.55.32 with SMTP id s32ls82021ibg.0.p; Wed, 03 Feb 2010 10:08:38 -0800 (PST) Received: by 10.231.170.74 with SMTP id c10mr752355ibz.1.1265220517799; Wed, 03 Feb 2010 10:08:37 -0800 (PST) Received: by 10.231.170.74 with SMTP id c10mr752354ibz.1.1265220517756; Wed, 03 Feb 2010 10:08:37 -0800 (PST) Return-Path: Received: from planchet.hinegardner.org (hinegardner.org [216.17.180.14]) by gmr-mx.google.com with ESMTP id 18si930031iwn.9.2010.02.03.10.08.37; Wed, 03 Feb 2010 10:08:37 -0800 (PST) Received-SPF: pass (google.com: domain of jeremy@hinegardner.org designates 216.17.180.14 as permitted sender) client-ip=216.17.180.14; Received: by planchet.hinegardner.org (Postfix, from userid 1000) id 388EE1599EC9; Wed, 3 Feb 2010 11:08:36 -0700 (MST) Date: Wed, 3 Feb 2010 11:08:36 -0700 From: Jeremy Hinegardner To: rack-devel@googlegroups.com Subject: Re: streaming api Message-ID: <20100203180835.GG16697@hinegardner.org> Reply-To: rack-devel@googlegroups.com Mail-Followup-To: rack-devel@googlegroups.com References: <3427BCA6-E591-470A-A628-F770D3A18F8C@gmail.com> MIME-Version: 1.0 In-Reply-To: <3427BCA6-E591-470A-A628-F770D3A18F8C@gmail.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jeremy@hinegardner.org designates 216.17.180.14 as permitted sender) smtp.mail=jeremy@hinegardner.org X-Original-Sender: jeremy@hinegardner.org Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rack-devel/t/5146e2033cfabda2 X-Message-Url: http://groups.google.com/group/rack-devel/msg/656cc7ad4cf25af4 Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 03, 2010 at 11:02:33AM +0000, James Tucker wrote: > > On 3 Feb 2010, at 04:47, Dominic Sisneros wrote: > > > The perl folks jumped on the rack & wsgi trend in a big way with psgi and are doing a lot of interesting stuff. > > > > One of the things that they have done differently is have an optional streaming interface. > > > > http://bulknews.typepad.com/blog/2009/10/psgiplack-streaming-is-now-complete.html > > > > So, basically the idea is the same as the original Python WSGI's start_response but this callback is NOT an optional parameter to the app because that stands in the way of everybody in the chain including middleware and that sucks. Instead, an app can optionally return a callback that accepts another callback to which you can return the response array ref (code, headers and body) if you want to delay your response. > > > > my $app = sub { > > my $env = shift; > > return sub { > > my $respond = shift; > > # do some event stuff > > $event->callback(sub { $respod->([ $code, $headers, $body ]) }); > > }; > > }; > > If you also want to delay the content body delivery as well (i.e. streaming) you can omit the body, in which case you'll get the writer object that has write(), close() and poll_cb(). > > > > my $app = sub { > > my $env = shift; > > return sub { > > my $respond = shift; > > my $w = $respond->([ 200, [ 'Content-Type' => 'text/plain' ]]); # no $body here > > # do more event stuff > > > > $event->callback(sub { $w->write($body) }); > > $event->done_callback(sub { $w->close }); > > }; > > }; > > > > That post also has links to other posts about their streaming rack like interface > > > > Should rack pursue something like this? > > > Yes this looks disturbingly familiar to my thin patches from 1.2 > You might want to also check out Rack::StreamingProxy http://github.com/aniero/rack-streaming-proxy enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org