Re: http server push
Igor Wojnicki <[email protected]> Tue, 15 Apr 2014 10:55:20 +0200
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Organization | KIS, AGH |
| Message-ID | <[email protected]> |
Jan,
Thanks. Sunday morning at work... ;)
I hoped it would just require prolog code alterations. Unfortunatelly I
don't have resources to investigate it that deep right now. I guess I'll
just stay with regular long poll for the application I need.
I'll try to get some students working on it.
Thanks again.
Hava a nice one.
On 04/13/2014 10:26 AM, Jan Wielemaker wrote:
> Igor,
>
> On 11-04-14 15:11, Igor Wojnicki wrote:
>> 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?
>
> That won't be really easy. Basically, the output of the handler is
> attached to a `cgi-stream', defined in cgi_stream.c of the http package.
> The stream is handled in http_wrapper.pl, notably cgi_hook/2. One option
> is to change some of the logic there that disables collecting the data
> and emits the header without a Content-length. The other option would
> be to use the same mechanism as http_reply_file/2. This throws an
> exception to get rid of the cgi-stream and talk directly to the
> underlying sockets. In both cases, it is an open question how to
> initiate this special mode. Probably this requires an additional
> predicate. Another option is to define a special header. For example:
>
> Content-length: close
>
> and pick this up in cgi_hook/2 to do the magic.
>
> Anyway, if you find a fairly clean solution, I'm happy to apply the
> patches.
>
> Hope this helps
>
> --- Jan
>
>
>>
>> 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
>>
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
--
Igor Wojnicki