[web-devel] Re: Lazy simpleHTTP
Henning Thielemann
lemming at henning-thielemann.de
Sun Nov 30 17:07:01 EST 2008
On Sat, 29 Nov 2008, Henning Thielemann wrote:
> On Sat, 29 Nov 2008, Henning Thielemann wrote:
>
>> On Thu, 27 Nov 2008, Henning Thielemann wrote:
>>
>>> I have HTTP-3001.0.4 and I like to check the HTTP response headers before
>>> downloading the entire document.
>>
>> I have tried to solve this on my own. I have written a wrapper to any
>> stream type. It first reads the entire document lazily into a string and
>> then ships its contents when readBlock or readLine is called. However, the
>> program blocks on 'close' now and I don't know why. (See
>> LazyStream.example)
>
> Is anyone else interested in getting HTTP response bodies lazily in general
> and trying my code in particular? Maybe some of the experts have an idea, why
> 'close' blocks.
I have got an idea by myself. On the one hand 'close' checks with a
pattern match whether the buffer is empty, on the other hand 'close'
checks whether the connection is active or closed. Both of these check
will certainly force the lazy read to be completed. But maybe the first
check is even wrong, since it aborts the program, if you close a
connection before reading it completely:
Network.Stream Network.TCP> s <- openTCPPort "ftp.tu-chemnitz.de" 80
Network.Stream Network.TCP> writeBlock s "GET /pub/linux/opensuse/distribution/11.0/iso/cd/openSUSE-11.0-KDE4-LiveCD-i386.iso HTTP/1.1\n"
Right ()
Network.Stream Network.TCP> writeBlock s "Host: ftp.tu-chemnitz.de\n"
Right ()
Network.Stream Network.TCP> writeBlock s "\n"
Right ()
Network.Stream Network.TCP> readLine s
Right "HTTP/1.1 200 OK\r\n"
Network.Stream Network.TCP> readLine s
Right "Date: Sun, 30 Nov 2008 21:58:43 GMT\r\n"
Network.Stream Network.TCP> close s
*** Exception: Network/TCP.hs:(166,10)-(172,17): Non-exhaustive patterns in function closeConn
This pattern is certainly the [] in
closeConn (MkConn sk addr [] _)
Is this a bug or a feature?
More information about the web-devel
mailing list