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

Subscribers are getting 403 with push_stream_authorized_channels_only. #62

Closed lazovskiy closed 11 years ago

lazovskiy commented 11 years ago

Hello.

I've faced a problem subscribing channels when push_stream_authorized_channels_only is "on". Server always responding with 403, even when i perform POST request to create an appropriate channel

config:

    location /pub/ {
            location ~ ^/pub/(?<channel_id>[A-Za-z0-9]+)$ {
                    allow 127.0.0.1;
                    deny all;

                    push_stream_publisher admin;
                    #push_stream_store_messages on;

                    set $push_stream_channel_id $channel_id;
            }
    }

    location /sub/ {
            location ~ /sub/(?<channel_id>[A-Za-z0-9]+)$ {
                    push_stream_subscriber long-polling;
                    push_stream_authorized_channels_only on;
                    set $push_stream_channels_path $channel_id;
            }
    }

testing:

curl --interface 127.0.0.1 -v -d TEST http://example.com/pub/7f276f2a1307cdb150d879b1d14a4879 ...

POST /pub/7f276f2a1307cdb150d879b1d14a4879 HTTP/1.1 User-Agent: curl/7.28.1 Host: example.com Accept: / Content-Length: 4 Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 4 out of 4 bytes < HTTP/1.1 200 OK < Server: nginx/1.3.10 < Date: Wed, 09 Jan 2013 17:11:43 GMT < Content-Type: application/json < Content-Length: 120 < Connection: close < Access-Control-Allow-Origin: * < {"channel": "7f276f2a1307cdb150d879b1d14a4879", "published_messages": "1", "stored_messages": "0", "subscribers": "0"}
  • Closing connection #0

curl --interface 127.0.0.1 -v -d TEST http://example.com/pub/7f276f2a1307cdb150d879b1d14a4879 ...

POST /pub/7f276f2a1307cdb150d879b1d14a4879 HTTP/1.1 User-Agent: curl/7.28.1 Host: example.com Accept: / Content-Length: 4 Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 4 out of 4 bytes < HTTP/1.1 200 OK < Server: nginx/1.3.10 < Date: Wed, 09 Jan 2013 17:11:45 GMT < Content-Type: application/json < Content-Length: 120 < Connection: close < Access-Control-Allow-Origin: * < {"channel": "7f276f2a1307cdb150d879b1d14a4879", "published_messages": "2", "stored_messages": "0", "subscribers": "0"}
  • Closing connection #0

published_messages is increasing, so I assume a channel is created.

But:

while true; do wget -O - http://example.com/sub/7f276f2a1307cdb150d879b1d14a4879; done

is still returning 403.

When push_stream_store_messages is enabled there is no problem subscribing a channel. But actually I don't want to queue messages and send all stored data to the subscriber. I would like to subscribe a channel after it has been created.

Any suggestions?

Thank you.

lazovskiy commented 11 years ago

1. Creating channel - OK.

host:~ # curl --interface 127.0.0.1 -v -d TEST http://example.com/pub/7f276f2a1307cdb150d879b1d14a4879
...
> POST /pub/7f276f2a1307cdb150d879b1d14a4879 HTTP/1.1
> User-Agent: curl/7.28.1
> Host: example.com
> Accept: */*
> Content-Length: 4
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 4 out of 4 bytes
< HTTP/1.1 200 OK
< Server: nginx/1.3.10
< Date: Thu, 10 Jan 2013 15:33:17 GMT
< Content-Type: application/json
< Content-Length: 120
< Connection: close
< Access-Control-Allow-Origin: *
<    
{"channel": "7f276f2a1307cdb150d879b1d14a4879", "published_messages": "1", "stored_messages": "0",     "subscribers": "0"}
* Closing connection #0

2. Getting channel stats - OK.

host:~ # curl --interface 127.0.0.1 -v  http://example.com/pub/7f276f2a1307cdb150d879b1d14a4879
...
> GET /pub/7f276f2a1307cdb150d879b1d14a4879 HTTP/1.1
> User-Agent: curl/7.28.1
> Host: example.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.3.10
< Date: Thu, 10 Jan 2013 15:33:26 GMT
< Content-Type: application/json
< Content-Length: 120
< Connection: close
< Access-Control-Allow-Origin: *
<
{"channel": "7f276f2a1307cdb150d879b1d14a4879", "published_messages": "1", "stored_messages": "0",     "subscribers": "0"}
* Closing connection #10 

3. Subscribing a channel - FAIL

host:~ # curl --interface 127.0.0.1 -v  http://example.com/sub/7f276f2a1307cdb150d879b1d14a4879
> GET /sub/7f276f2a1307cdb150d879b1d14a4879 HTTP/1.1
> User-Agent: curl/7.28.1
> Host: example.com
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: nginx/1.3.10
< Date: Thu, 10 Jan 2013 15:33:43 GMT
< Content-Length: 0
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET
< Access-Control-Allow-Headers: If-Modified-Since,If-None-Match
< X-Nginx-PushStream-Explain: Subscriber could not create channels.
<
wandenberg commented 11 years ago

yes, this is the defined behavior. the push_stream_authorized_channels_only on, means that the channels has to have at least one message. So, to use push_stream_authorized_channels_only with on, you have to set push_stream_store_messages as on, and define how many messages you want to store or how long do you want to store than, you can combine this two directives, as example, save 10 messages to at most 5 seconds.