Problems with the client example
close(S) should be
More interestingly, the example does not work if
~n does not resolve to CR+LF: The request line and other header fields must each end with CR+LF.
It doesn't work on my local Apache Server (error 400), altough www.swi-prolog.org uses 'varnish' which seems to be lenient and can handle a single LF.
dump_swi_homepage(Host) :- must_be(atom,Host), % must be an atom or tcp_connect/3 will protest setup_call_cleanup( tcp_connect(Host:http, Stream, ), ( EOL='\u000D\u000A', format(Stream, 'GET / HTTP/1.1~a\c Host: ~a~a\c Connection: close~a\c ~a', [EOL,Host,EOL,EOL,EOL]), flush_output(Stream), copy_stream_data(Stream, current_output) ), close(Stream)).