SWI-Prolog / packages-http

The SWI-Prolog HTTP server and client libraries
23 stars 23 forks source link

Keep-alive and zero length response raise domain_error(nonneg) #141

Closed esad closed 4 years ago

esad commented 4 years ago

This is because 0 gets passed to stream_range_open/3 which wants Bytes to be > 0. What should we do in this case? I thought we could just fail and the next rule which leaves the stream unchanged would kick in:

diff --git a/http_open.pl b/http_open.pl
index c228abb..2b6d33c 100644
--- a/http_open.pl
+++ b/http_open.pl
@@ -1468,20 +1468,21 @@ http_scheme(https).
 %!  consider_keep_alive(+HeaderLines, +Parts, +Host,
 %!                      +Stream0, -Stream,
 %!                      +Options) is det.

 consider_keep_alive(Lines, Parts, Host, StreamPair, In, Options) :-
     option(connection(Asked), Options),
     keep_alive(Asked),
     connection(Lines, Given),
     keep_alive(Given),
     content_length(Lines, Bytes),
+    Bytes > 0,
     !,
     stream_pair(StreamPair, In0, _),
     connection_address(Host, Parts, HostPort),
     debug(http(connection),
           'Keep-alive to ~w (~D bytes)', [HostPort, Bytes]),
     stream_range_open(In0, In,
                       [ size(Bytes),
                         onclose(keep_alive(StreamPair, HostPort))
                       ]).
 consider_keep_alive(_, _, _, Stream, Stream, _).

But then we'd lose the keep alive. Can stream_range_open be made accept 0 values?

JanWielemaker commented 4 years ago

Can stream_range_open be made accept 0 values?

Thanks. Pushed a fix that allows zero-length range streams (actually seems a typo that this was not allowed).