Permalink
Browse files

Merge erikh push_ignore_queue_on_no_cache.

I don't buy the cors_allow feature, because arbitrary headers can already be
set up through the nginx config file.
  • Loading branch information...
1 parent 9b03c57 commit e7ea1b4eceebbb661b4c30a72cb984e87f3bb899 @jedisct1 committed May 21, 2010
Showing with 40 additions and 6 deletions.
  1. +26 −5 src/ngx_http_push_module.c
  2. +5 −0 src/ngx_http_push_module.h
  3. +9 −1 src/ngx_http_push_module_setup.c
View
@@ -295,9 +295,15 @@ static ngx_int_t ngx_http_push_subscriber_handler(ngx_http_request_t *r) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
}
- msg = ngx_http_push_find_message_locked(channel, r, &msg_search_outcome);
- channel->last_seen = ngx_time();
- ngx_shmtx_unlock(&shpool->mutex);
+
+ msg = ngx_http_push_find_message_locked(channel, r, &msg_search_outcome);
+ channel->last_seen = ngx_time();
+ ngx_shmtx_unlock(&shpool->mutex);
+
+ if (cf->ignore_queue_on_no_cache && !ngx_http_push_allow_caching(r)) {
+ msg_search_outcome = NGX_HTTP_PUSH_MESSAGE_EXPECTED;
+ msg = NULL;
+ }
switch(ngx_http_push_handle_subscriber_concurrency(r, channel, cf)) {
case NGX_DECLINED: //this request was declined for some reason.
@@ -391,7 +397,7 @@ static ngx_int_t ngx_http_push_subscriber_handler(ngx_http_request_t *r) {
r->read_event_handler = ngx_http_test_reading;
r->write_event_handler = ngx_http_request_empty_handler;
r->discard_body = 1;
- r->keepalive=1; //stayin' alive!!
+ r->keepalive = 1; //stayin' alive!!
return NGX_DONE;
case NGX_HTTP_PUSH_MECHANISM_INTERVALPOLL:
@@ -464,7 +470,6 @@ static ngx_int_t ngx_http_push_subscriber_handler(ngx_http_request_t *r) {
clnf->name = chain->buf->file->name.data;
clnf->log = r->pool->log;
}
-
return ngx_http_push_prepare_response_to_subscriber_request(r, chain, content_type, etag, last_modified);
@@ -1041,6 +1046,22 @@ static ngx_int_t ngx_http_push_subscriber_get_etag_int(ngx_http_request_t * r) {
return ngx_abs(tag);
}
+static ngx_int_t ngx_http_push_allow_caching(ngx_http_request_t * r) {
+ ngx_str_t *tmp_header;
+ ngx_str_t header_checks[2] = { NGX_HTTP_PUSH_HEADER_CACHE_CONTROL, NGX_HTTP_PUSH_HEADER_PRAGMA };
+ ngx_int_t i = 0;
+
+ for(; i < 2; i++) {
+ tmp_header = ngx_http_push_find_in_header_value(r, header_checks[i]);
+
+ if (tmp_header != NULL) {
+ return !!ngx_strncasecmp(tmp_header->data, NGX_HTTP_PUSH_CACHE_CONTROL_VALUE.data, tmp_header->len);
+ }
+ }
+
+ return 1;
+}
+
static ngx_str_t * ngx_http_push_subscriber_get_etag(ngx_http_request_t * r) {
ngx_uint_t i;
ngx_list_part_t *part = &r->headers_in.headers.part;
@@ -62,6 +62,7 @@ typedef struct {
ngx_str_t channel_group;
ngx_int_t max_channel_id_length;
ngx_int_t max_channel_subscribers;
+ ngx_int_t ignore_queue_on_no_cache;
} ngx_http_push_loc_conf_t;
//message queue
@@ -165,6 +166,7 @@ static ngx_int_t ngx_http_push_broadcast_locked(ngx_http_push_channel_t *channel
#define ngx_http_push_broadcast_message_locked(channel, msg, log, shpool) ngx_http_push_broadcast_locked(channel, msg, 0, NULL, log, shpool)
static ngx_int_t ngx_http_push_respond_to_subscribers(ngx_http_push_channel_t *channel, ngx_http_push_subscriber_t *sentinel, ngx_http_push_msg_t *msg, ngx_int_t status_code, const ngx_str_t *status_line);
+static ngx_int_t ngx_http_push_allow_caching(ngx_http_request_t * r);
static ngx_int_t ngx_http_push_subscriber_get_etag_int(ngx_http_request_t * r);
static ngx_str_t * ngx_http_push_subscriber_get_etag(ngx_http_request_t * r);
static void ngx_http_push_subscriber_cleanup(ngx_http_push_subscriber_cleanup_t *data);
@@ -189,6 +191,9 @@ const ngx_str_t NGX_HTTP_PUSH_HEADER_ETAG = ngx_string("Etag");
const ngx_str_t NGX_HTTP_PUSH_HEADER_IF_NONE_MATCH = ngx_string("If-None-Match");
const ngx_str_t NGX_HTTP_PUSH_HEADER_VARY = ngx_string("Vary");
const ngx_str_t NGX_HTTP_PUSH_HEADER_ALLOW = ngx_string("Allow");
+const ngx_str_t NGX_HTTP_PUSH_HEADER_CACHE_CONTROL = ngx_string("Cache-Control");
+const ngx_str_t NGX_HTTP_PUSH_HEADER_PRAGMA = ngx_string("Pragma");
+
//header values
const ngx_str_t NGX_HTTP_PUSH_CACHE_CONTROL_VALUE = ngx_string("no-cache");
@@ -105,6 +105,7 @@ static void * ngx_http_push_create_loc_conf(ngx_conf_t *cf) {
lcf->delete_oldest_received_message=NGX_CONF_UNSET;
lcf->max_channel_id_length=NGX_CONF_UNSET;
lcf->max_channel_subscribers=NGX_CONF_UNSET;
+ lcf->ignore_queue_on_no_cache=NGX_CONF_UNSET;
lcf->channel_group.data=NULL;
return lcf;
}
@@ -121,6 +122,7 @@ static char * ngx_http_push_merge_loc_conf(ngx_conf_t *cf, void *parent, void *c
ngx_conf_merge_value(conf->delete_oldest_received_message, prev->delete_oldest_received_message, 0);
ngx_conf_merge_value(conf->max_channel_id_length, prev->max_channel_id_length, NGX_HTTP_PUSH_MAX_CHANNEL_ID_LENGTH);
ngx_conf_merge_value(conf->max_channel_subscribers, prev->max_channel_subscribers, 0);
+ ngx_conf_merge_value(conf->ignore_queue_on_no_cache, prev->ignore_queue_on_no_cache, 0);
ngx_conf_merge_str_value(conf->channel_group, prev->channel_group, "");
//sanity checks
@@ -352,7 +354,13 @@ static ngx_command_t ngx_http_push_commands[] = {
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_push_loc_conf_t, max_channel_subscribers),
NULL },
-
+ { ngx_string("push_ignore_queue_on_no_cache"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_push_loc_conf_t, ignore_queue_on_no_cache),
+ NULL },
+
ngx_null_command
};

0 comments on commit e7ea1b4

Please sign in to comment.