wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

push_stream_[header,footer]_template is not sent on subscriber timeout #47

Closed gigiu closed 10 years ago

gigiu commented 12 years ago

hi, first of all thanks for your amazing work

i have a problem, pushstream[header,footer]_template is not sent when push_stream_longpolling_connection_ttl occur.

i use last version of nginx-push-stream-module

my simple config:

[nginx config file]
    push_stream_max_messages_stored_per_channel 1;
    push_stream_message_ttl 5m;

[vhost file]
    location /pub {
        # activate publisher (admin) mode for this location
        push_stream_publisher admin;
        push_stream_store_messages on;
        # query string based channel id
        set $push_stream_channel_id             $arg_id;
    }

    location ~ /lp/(.*) {
        # activate long-polling mode for this location
        push_stream_subscriber      long-polling;

        # positional channel path
        set $push_stream_channels_path    $1;

        # message template
        push_stream_header_template "[";
        push_stream_message_template "'{\"id\":~id~,\"text\":\"~text~\"}'";
        push_stream_footer_template "]";

        # connection timeout
        push_stream_longpolling_connection_ttl        30s;

    }

thanks in advance for your help :)

wandenberg commented 12 years ago

hi, this is the expected behavior. When a timeout happens you only receive a 304 header response. The header and footer templates are sent only when a message is sent. Your client has to be prepared to this behavior. You can use the pushstream.js, it handle this for you.

Regards

gigiu commented 12 years ago

mmm, so i guess you should fix your docs

push_stream_footer_template  
syntax: push_stream_footer_template string
default: none
context: location (push_stream_subscriber)
release version: 0.2.6
The text that will be sended to subscribers before connection is closed (channel deleted ou subscriber timeout).

anyway i cant use pushstream.js, i need this for the api part of the site, and i need a custom message when timeout happen, there is any chance to get a simple patch for this?

thanks in advance

gigiu commented 12 years ago

hi, any news on this? any change to have some sort of push_stream_timeout_message_text?

thanks again

wandenberg commented 12 years ago

hi. Sorry for the late response. I was checking the code and documentation and, in fact the documentation is incomplete. The header/footer template is sent on stream connections in which a timeout happens. When I added the long polling support, on versions 0.3.0/0.3.1, I forgot to update the docs, because a timeout on long polling never sent those templates. You can achieve what you want using the status code, if is a 200 the subscriber received a message, if is a 304 a timeout happened, and you can use your custom behaviour.

I will review the docs for the next version.

regards, Wandenberg

vash1486 commented 12 years ago

Hi! I've a similar problem: considering a jsonp request you can't read the response header (and, then, neither the status code), so it is not possible to know if a void response is a real void response or the server k.o. (for instance). Therefore I think that it will be great to have the ability (simply a trua/false flag) to send header/footer in any case (so a "void" response will have readable header and footer, while a k.o. server will be simply "void")

Thanks for your work ^_^

wandenberg commented 10 years ago

This was solved on tag 0.4.0 3d3a204177d3a7ab8a2858e04e792a6d11bf133f Now you can set to receive a complete response when a timeout happens.