Re: http server push

Igor Wojnicki <[email protected]> Fri, 11 Apr 2014 15:11:15 +0200
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Jan,

Thanks for the reply.

Your example, with the transfer encoding works fine as long as the 
client requests HTTP/1.1.  The chunked encoding doesn't work with 
HTTP/1.0 though. I'd rather go without chunked encoding, esp. that it 
has to be supported by the client.

It seems that using flush_output/0, while replying to a HTTP/1.0 request 
doesn't flush the buffer, the client does not receive data. Is it a bug 
or a feature?

Of course it can be assumed that nobody uses HTTP/1.0 anymore but I'd 
appreciate if I could flush the output buffer and have this partial 
transfer working no matter HTTP version or transfer mode. Could you 
point me what to change in the http* modules to make it work this way?

By the way I use swi 6.2.6.

Thanks again,
Igor.

On 04/11/2014 12:22 PM, Jan Wielemaker wrote:
> It works like this:
>
> :- use_module(library(http/http_dispatch)).
> :- use_module(library(http/thread_httpd)).
> :- http_handler(root(longpoll), longpoll, [time_limit(5)]).
>
> server :-
>      http_server(http_dispatch, [port(4000)]).
>
> longpoll(_Request) :-
>      format('Transfer-Encoding: chunked~n'),
>      format('Content-type: text/plain~n~n'),
>      format('testing~n'),
>      flush_output,
>      sleep(2),
>      format('testing~n').
>
> I.e., you need chunked transfer encoding and you need to flush.
>
>      Cheers --- Jan

-- 
Igor Wojnicki