[squeak-dev] Re: [ANN] WebClient and WebServer 1.0 for Squeak

Andreas Raab andreas.raab at gmx.de
Tue May 11 16:21:05 UTC 2010


On 5/11/2010 7:52 AM, Igor Stasenko wrote:
> just one feature request: support streaming in WebClient,
> i.e. apart from being able to fetch a response content in a single blob,
> also provide an API, which would enable WebClient user to read content
> step by step, by using stream protocol, i.e. #next, #next: etc.
>
> I see you having a #streamFrom:to:size:progress:
> in WebMessage, but its a little bit too high level (requires an output
> stream and includes a progress block)
> and its end consumer is a #content message.
>
> It would be nice to have something like:
>
> response := WebClient httpGet: 'http://foo.bar'.
>
> content := response content. "read all at once".

That works out of the box.

> contentStream := response contentStream.  "read content using a stream"
> [contentStream atEnd] whileFalse: [
>    c := contentStream next.  ....
> ].

And that works out of the box, too :-) With a small modification. The 
convenience APIs on the class side close the client and prefetch the 
response. In other words, in order to stream you need to write, e.g,

   client := WebClient new.
   [resp := client httpGet:'http://www.squeak.org'.
   length := resp contentLength.
   stream := resp contentStream.
   [length > 0] whileTrue:[
     stream next: (length min: 100).
   ]] ensure:[stream close].

A couple of things to keep in mind though: The above doesn't deal with 
the server returning an HTTP/1.0 response (no content-length) or other 
specialties like chunked-encoding content transfer. That's why the 
high-level functions are advantageous because they deal with all of that.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list