ngx_http_filter_finalize_request() and ngx_http_clean_header()

This commit is contained in:
Igor Sysoev 2009-05-01 18:41:07 +00:00
parent b01c9cc10e
commit 71d1f49268
3 changed files with 40 additions and 19 deletions

View File

@ -64,7 +64,6 @@ typedef struct {
static ngx_int_t ngx_http_xslt_send(ngx_http_request_t *r,
ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b);
static ngx_int_t ngx_http_xslt_filter_internal_error(ngx_http_request_t *r);
static ngx_int_t ngx_http_xslt_add_chunk(ngx_http_request_t *r,
ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b);
@ -320,14 +319,15 @@ ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
ctx->done = 1;
if (b == NULL) {
return ngx_http_xslt_filter_internal_error(r);
return ngx_http_filter_finalize_request(r,
NGX_HTTP_INTERNAL_SERVER_ERROR);
}
cln = ngx_pool_cleanup_add(r->pool, 0);
if (cln == NULL) {
ngx_free(b->pos);
return ngx_http_special_response_handler(r,
return ngx_http_filter_finalize_request(r,
NGX_HTTP_INTERNAL_SERVER_ERROR);
}
@ -359,22 +359,6 @@ ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
}
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_add_chunk(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
ngx_buf_t *b)

View File

@ -103,6 +103,9 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
ngx_int_t ngx_http_send_header(ngx_http_request_t *r);
ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r,
ngx_int_t error);
ngx_int_t ngx_http_filter_finalize_request(ngx_http_request_t *r,
ngx_int_t error);
void ngx_http_clean_header(ngx_http_request_t *r);
time_t ngx_http_parse_time(u_char *value, size_t len);

View File

@ -445,6 +445,40 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
}
ngx_int_t
ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_int_t error)
{
ngx_int_t rc;
ngx_http_clean_header(r);
/* clear the modules contexts */
ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
rc = ngx_http_special_response_handler(r, error);
/* NGX_ERROR resets any pending data */
return (rc == NGX_OK) ? NGX_ERROR : rc;
}
void
ngx_http_clean_header(ngx_http_request_t *r)
{
ngx_memzero(&r->headers_out.status,
sizeof(ngx_http_headers_out_t)
- offsetof(ngx_http_headers_out_t, status));
r->headers_out.headers.part.nelts = 0;
r->headers_out.headers.part.next = NULL;
r->headers_out.headers.last = &r->headers_out.headers.part;
r->headers_out.content_length_n = -1;
r->headers_out.last_modified_time = -1;
}
static ngx_int_t
ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
{