static ngx_int_t ngx_http_xslt_filter_internal_error(ngx_http_request_t *r) { ngx_int_t rc; /* clear the modules contexts */ ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); rc = ngx_http_special_response_handler(r, NGX_HTTP_INTERNAL_SERVER_ERROR); /* NGX_ERROR resets any pending data */ return (rc == NGX_OK) ? NGX_ERROR : rc; }
static ngx_int_t ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b) { ngx_int_t rc; ngx_chain_t out; ngx_pool_cleanup_t *cln; ctx->done = 1; if (b == NULL) { return ngx_http_xslt_filter_internal_error(r); } cln = ngx_pool_cleanup_add(r->pool, 0); if (cln == NULL) { ngx_free(b->pos); return ngx_http_special_response_handler(r, NGX_HTTP_INTERNAL_SERVER_ERROR); } if (r == r->main) { r->headers_out.content_length_n = b->last - b->pos; if (r->headers_out.content_length) { r->headers_out.content_length->hash = 0; r->headers_out.content_length = NULL; } ngx_http_clear_last_modified(r); } rc = ngx_http_next_header_filter(r); if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { ngx_free(b->pos); return rc; } cln->handler = ngx_http_xslt_cleanup; cln->data = b->pos; out.buf = b; out.next = NULL; return ngx_http_next_body_filter(r, &out); }
ngx_int_t ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_module_t *m, ngx_int_t error) { void *ctx; ngx_int_t rc; ngx_http_clean_header(r); ctx = NULL; if (m) { ctx = r->ctx[m->ctx_index]; } /* clear the modules contexts */ ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); if (m) { r->ctx[m->ctx_index] = ctx; } r->filter_finalize = 1; rc = ngx_http_special_response_handler(r, error); /* NGX_ERROR resets any pending data */ switch (rc) { case NGX_OK: case NGX_DONE: return NGX_ERROR; default: return rc; } }
static ngx_int_t ngx_http_zip_main_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_http_zip_ctx_t *ctx; ngx_chain_t *chain_link; int rc; ctx = ngx_http_get_module_ctx(r, ngx_http_zip_module); if (ctx == NULL || ctx->trailer_sent) { return ngx_http_next_body_filter(r, in); } if (ctx->abort) { return NGX_ERROR; } if (r->headers_out.status != NGX_HTTP_OK && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT) { return ngx_http_next_body_filter(r, in); } if (ctx->parsed) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "mod_zip: restarting subrequests"); return ngx_http_zip_send_pieces(r, ctx); } if (in == NULL) { return ngx_http_next_body_filter(r, NULL); } rc = ngx_http_zip_copy_unparsed_request(r, in, ctx); if (rc == NGX_AGAIN) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "mod_zip: not the last buf"); return ngx_http_zip_discard_chain(r, in); } else if (rc == NGX_ERROR) { return NGX_ERROR; } ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "mod_zip: about to parse list"); if (ngx_http_zip_parse_request(ctx) == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "mod_zip: invalid file list from upstream"); return NGX_ERROR; } if (ngx_http_zip_generate_pieces(r, ctx) == NGX_ERROR) { return NGX_ERROR; } if (!r->header_sent) { rc = ngx_http_zip_set_headers(r, ctx); if (rc == NGX_ERROR) { return NGX_ERROR; } if (rc == NGX_HTTP_RANGE_NOT_SATISFIABLE) { return ngx_http_special_response_handler(r, rc); } if ((rc = ngx_http_send_header(r)) != NGX_OK) { return rc; } } chain_link = ngx_chain_last_link(in); chain_link->buf->last_buf = 0; if (ngx_http_zip_strip_range_header(r) == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "mod_zip: failed to strip Range: header from request"); return NGX_ERROR; } return ngx_http_zip_send_pieces(r, ctx); }
ngx_int_t ngx_http_kafka_enq_buf(ngx_http_request_t *r, ngx_http_kafka_ctx_t *ctx) { ngx_http_kafka_main_conf_t *kmcf; ngx_http_kafka_upstream_t *u; ngx_kfk_broker_t *broker; ngx_kfk_buf_t *buf; ngx_chain_t *cl; ngx_str_t *msg; buf = ctx->toppar->free; msg = ctx->msg; cl = ngx_http_kafka_get_free_chain(buf->kfk, &buf->kfk->free_chain, (ngx_buf_tag_t)&ngx_http_kafka_module); if (cl == NULL) { ngx_http_kafka_recycle_msg(buf->pool, msg); return NGX_HTTP_SERVICE_UNAVAILABLE; } /* TODO compression */ cl->buf->pos = msg->data; cl->buf->last = cl->buf->pos + msg->len; /* msgset size */ ngx_kfk_header_msgset_size(buf) += ngx_buf_size(cl->buf); *buf->last_chain = cl; buf->last_chain = &cl->next; buf->cnt++; buf->kfk->pending_msgs_cnt++; kmcf = ngx_http_get_module_main_conf(r, ngx_http_kafka_module); #if (NGX_KFK_STATUS) if (kmcf->status) { (void)ngx_atomic_fetch_add(ngx_kfk_pending_msgs, 1); } #endif if (buf->cnt >= kmcf->batch_size) { ngx_http_kafka_toppar_free_to_out(ctx->toppar); broker = ctx->toppar->broker; if (broker != NULL && broker->state == NGX_KFK_BROKER_UP) { u = broker->upstream; ngx_http_kafka_upstream_enable_write_event(broker, u); u->send_request(broker, u); } } else if (buf->cnt == 1) { /* add a timer for each partition to achieve delayed sending */ ngx_add_timer(&ctx->toppar->send_timer, kmcf->linger); } return ngx_http_special_response_handler(r, NGX_HTTP_OK); }