static ngx_int_t internal_respond_status(subscriber_t *self, ngx_int_t status_code, const ngx_str_t *status_line) { internal_subscriber_t *f = (internal_subscriber_t *)self; DBG("%p status %i", self, status_code); if(status_code == NGX_HTTP_GONE) { self->dequeue_after_response = 1; } f->respond_status(status_code, (void *)status_line, f->privdata); reset_timer(f); return dequeue_maybe(self); }
static ngx_int_t internal_respond_message(subscriber_t *self, nchan_msg_t *msg) { internal_subscriber_t *f = (internal_subscriber_t *)self; verify_subscriber_last_msg_id(self, msg); DBG("%p (%s) respond msg %p", self, f->sub.name, msg); f->respond_message(NGX_OK, msg, f->privdata); reset_timer(f); return dequeue_maybe(self); }
static ngx_int_t longpoll_respond_status(subscriber_t *self, ngx_int_t status_code, const ngx_str_t *status_line) { full_subscriber_t *fsub = (full_subscriber_t *)self; ngx_http_request_t *r = fsub->sub.request; nchan_request_ctx_t *ctx = ngx_http_get_module_ctx(r, nchan_module); nchan_loc_conf_t *cf = fsub->sub.cf; if(fsub->data.act_as_intervalpoll) { if(status_code == NGX_HTTP_NO_CONTENT || status_code == NGX_HTTP_NOT_MODIFIED || status_code == NGX_HTTP_NOT_FOUND ) { status_code = NGX_HTTP_NOT_MODIFIED; } } else if(status_code == NGX_HTTP_NO_CONTENT || status_code == NGX_HTTP_NOT_MODIFIED) { if(cf->longpoll_multimsg) { if(fsub->data.multimsg_first != NULL) { longpoll_multimsg_respond(fsub); dequeue_maybe(self); } return NGX_OK; } else { //don't care, ignore return NGX_OK; } } DBG("%p respond req %p status %i", self, r, status_code); nchan_set_msgid_http_response_headers(r, &self->last_msgid); //disable abort handler fsub->data.cln->handler = empty_handler; if(ctx->request_origin_header.len > 0) { nchan_add_response_header(r, &NCHAN_HEADER_ALLOW_ORIGIN, &cf->allow_origin); } nchan_respond_status(r, status_code, status_line, 0); dequeue_maybe(self); return NGX_OK; }
static ngx_int_t longpoll_respond_status(subscriber_t *self, ngx_int_t status_code, const ngx_str_t *status_line) { full_subscriber_t *fsub = (full_subscriber_t *)self; ngx_http_request_t *r = fsub->sub.request; nchan_loc_conf_t *cf = fsub->sub.cf; //DBG("%p got status %i", self, status_code); if(fsub->data.act_as_intervalpoll) { if(status_code == NGX_HTTP_NO_CONTENT || status_code == NGX_HTTP_NOT_MODIFIED || status_code == NGX_HTTP_NOT_FOUND ) { status_code = NGX_HTTP_NOT_MODIFIED; } } else if(status_code == NGX_HTTP_NO_CONTENT || (status_code == NGX_HTTP_NOT_MODIFIED && !status_line)) { if(cf->longpoll_multimsg) { if(fsub->data.multimsg_first != NULL) { longpoll_multipart_respond(fsub); dequeue_maybe(self); } return NGX_OK; } else { //don't care, ignore return NGX_OK; } } DBG("%p respond req %p status %i", self, r, status_code); fsub->sub.dequeue_after_response = 1; nchan_set_msgid_http_response_headers(r, NULL, &self->last_msgid); //disable abort handler fsub->data.cln->handler = empty_handler; nchan_respond_status(r, status_code, status_line, 0); dequeue_maybe(self); return NGX_OK; }
static ngx_int_t longpoll_respond_message(subscriber_t *self, nchan_msg_t *msg) { full_subscriber_t *fsub = (full_subscriber_t *)self; ngx_int_t rc; char *err = NULL; ngx_http_request_t *r = fsub->sub.request; nchan_request_ctx_t *ctx = ngx_http_get_module_ctx(r, nchan_module); nchan_loc_conf_t *cf = fsub->sub.cf; DBG("%p respond req %p msg %p", self, r, msg); ctx->prev_msg_id = self->last_msgid; update_subscriber_last_msg_id(self, msg); ctx->msg_id = self->last_msgid; //disable abort handler fsub->data.cln->handler = empty_handler; //verify_unique_response(&fsub->data.request->uri, &self->last_msgid, msg, self); if(!cf->longpoll_multimsg) { assert(fsub->data.already_responded != 1); fsub->data.already_responded = 1; if(ctx->request_origin_header.len > 0) { nchan_add_response_header(r, &NCHAN_HEADER_ALLOW_ORIGIN, &cf->allow_origin); } if((rc = nchan_respond_msg(r, msg, &self->last_msgid, 0, &err)) != NGX_OK) { return abort_response(self, err); } } else { if((rc = longpoll_multimsg_add(fsub, msg, &err)) != NGX_OK) { return abort_response(self, err); } } dequeue_maybe(self); return rc; }
static ngx_int_t longpoll_respond_message(subscriber_t *self, nchan_msg_t *msg) { full_subscriber_t *fsub = (full_subscriber_t *)self; ngx_int_t rc; char *err = NULL; ngx_http_request_t *r = fsub->sub.request; nchan_request_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_nchan_module); nchan_loc_conf_t *cf = fsub->sub.cf; DBG("%p respond req %p msg %p", self, r, msg); ctx->prev_msg_id = self->last_msgid; update_subscriber_last_msg_id(self, msg); ctx->msg_id = self->last_msgid; //verify_unique_response(&fsub->data.request->uri, &self->last_msgid, msg, self); if(fsub->data.timeout_ev.timer_set) { ngx_del_timer(&fsub->data.timeout_ev); } if(!cf->longpoll_multimsg) { //disable abort handler fsub->data.cln->handler = empty_handler; assert(fsub->data.already_responded != 1); fsub->data.already_responded = 1; if((rc = nchan_respond_msg(r, msg, &self->last_msgid, 0, &err)) != NGX_OK) { return abort_response(self, err); } } else { if((rc = longpoll_multipart_add(fsub, msg, &err)) != NGX_OK) { return abort_response(self, err); } } dequeue_maybe(self); return rc; }
static ngx_int_t abort_response(subscriber_t *sub, char *errmsg) { ERR("abort! %s", errmsg ? errmsg : "unknown error"); dequeue_maybe(sub); return NGX_ERROR; }