checking if content was downloaded completly

21 views
Skip to first unread message

Thomas Klausner

unread,
Oct 29, 2012, 11:44:31 AM10/29/12
to psgi-...@googlegroups.com
No response yet on IRC, so I try here:

10:06 < domm> hey, I've got a questions regarding a streaming plack app (i.e.
              not a middleware)
10:06 < domm> after sending a file, I need to send a request to another server
              (but only if the whole file was transmitted)
10:06 < domm> I've come up with something like this:
10:06 < domm> http://domm.plix.at/share/plack.stream.txt
10:07 < domm> which works if run via plackup, but not if run via eg Starman
10:07 < domm> I assume because I need to do some response_cb magic?
10:08 < domm> but as I'm not doing a middleware, I cannot get a $res via
              $app->($env)
10:08 < domm> any ideas/pointers?

Also, after looking at the Starman source code (sub _finalize_response), it seems to me that a plack App and a webserver like Starman behave like a webapp behind a proxy, i.e. the whole content is sent to the proxy (starman) which then transfers it to the user. Which means it's not possible to check if the whole content arrived at the user.

So is there any way to fire an http request after a download is completed?

(more context, if you care: one customer (public radio station) provides a download service where users can download a limited amount of programs as mp3. we can only deduct the download from each users count if we're rather sure the user got the whole file. currently this is implemented in some oldschool catalyst (pre-plack) and some similar fuzzing with ->write as in the sample I showed. I now want to update the app, and split the download thingy into a small standalone server (Plack & Starman (or whatever)). )

Greetings,
domm





Tatsuhiko Miyagawa

unread,
Oct 29, 2012, 1:14:07 PM10/29/12
to psgi-...@googlegroups.com
Your sample code seems to be checking the return value of ->write to
check if it's actually written, and that is not a behavior defined in
the PSGI specification but happens to be implemented in
HTTP::Server::PSGI and Starlet.

avar proposed to add something similar to the PSGI specification:
https://github.com/plack/psgi-specs/wiki/Proposal:-Return-values-for-PSGI-streaming-functions

I think it makes sense in the blocking server implementation but maybe
not so much in async/non-blocking servers since mostly ->write method
there is to queue up the data write.
--
Tatsuhiko Miyagawa
Reply all
Reply to author
Forward
0 new messages