#include #include #include #include #include #include static char error_tail[] = "
" NGINX_VER "
" CRLF "" CRLF "" CRLF ; static char error_400_page[] = "" CRLF "400 Bad Request" CRLF "" CRLF "

400 Bad Request

" CRLF ; static char error_403_page[] = "" CRLF "403 Forbidden" CRLF "" CRLF "

403 Forbidden

" CRLF ; static char error_404_page[] = "" CRLF "404 Not Found" CRLF "" CRLF "

404 Not Found

" CRLF ; static char error_408_page[] = "" CRLF "408 Request Time-out" CRLF "" CRLF "

408 Request Time-out

" CRLF ; static char error_414_page[] = "" CRLF "414 Request-URI Too Large" CRLF "" CRLF "

414 Request-URI Too Large

" CRLF ; static char error_500_page[] = "" CRLF "500 Internal Server Error" CRLF "" CRLF "

500 Internal Server Error

" CRLF ; static char error_502_page[] = "" CRLF "502 Bad Gateway" CRLF "" CRLF "

502 Bad Gateway

" CRLF ; static char error_504_page[] = "" CRLF "504 Gateway Time-out" CRLF "" CRLF "

504 Gateway Time-out

" CRLF ; static ngx_str_t error_pages[] = { ngx_null_string, /* 301 */ ngx_null_string, /* 302 */ ngx_null_string, /* 303 */ ngx_string(error_400_page), ngx_null_string, /* 401 */ ngx_null_string, /* 402 */ ngx_string(error_403_page), ngx_string(error_404_page), ngx_null_string, /* 405 */ ngx_null_string, /* 406 */ ngx_null_string, /* 407 */ ngx_string(error_408_page), ngx_null_string, /* 409 */ ngx_null_string, /* 410 */ ngx_null_string, /* 411 */ ngx_null_string, /* 412 */ ngx_null_string, /* 413 */ ngx_string(error_414_page), ngx_null_string, /* 415 */ ngx_null_string, /* 416 */ ngx_string(error_500_page), ngx_null_string, /* 501 */ ngx_string(error_502_page), ngx_null_string, /* 503 */ ngx_string(error_504_page) }; int ngx_http_special_response_handler(ngx_http_request_t *r, int error) { int err, len; ngx_hunk_t *message, *tail; len = 0; r->headers_out.status = error; if (error < NGX_HTTP_BAD_REQUEST) { /* 3XX */ err = error - NGX_HTTP_MOVED_PERMANENTLY; } else { ngx_test_null(r->headers_out.content_type, ngx_push_table(r->headers_out.headers), NGX_HTTP_INTERNAL_SERVER_ERROR); r->headers_out.content_type->key.len = 12; r->headers_out.content_type->key.data = "Content-Type"; r->headers_out.content_type->value.len = 9; r->headers_out.content_type->value.data = "text/html"; if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) { /* 4XX */ err = error - NGX_HTTP_BAD_REQUEST + 3; } else { /* 5XX */ err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17; } } if (r->keepalive != 0) { switch (error) { case NGX_HTTP_BAD_REQUEST: case NGX_HTTP_REQUEST_URI_TOO_LARGE: case NGX_HTTP_INTERNAL_SERVER_ERROR: r->keepalive = 0; } } if (r->lingering_close == 1) { switch (error) { case NGX_HTTP_BAD_REQUEST: case NGX_HTTP_REQUEST_URI_TOO_LARGE: case NGX_HTTP_INTERNAL_SERVER_ERROR: r->lingering_close = 0; } } if (error_pages[err].len == 0) { r->headers_out.content_length = -1; } else { r->headers_out.content_length = error_pages[err].len + len + sizeof(error_tail); } if (ngx_http_send_header(r) == NGX_ERROR) { return NGX_ERROR; } if (error_pages[err].len == 0) { return NGX_OK; } ngx_test_null(message, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); message->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; message->pos = error_pages[err].data; message->last = error_pages[err].data + error_pages[err].len; if (ngx_http_output_filter(r, message) == NGX_ERROR) { return NGX_ERROR; } ngx_test_null(tail, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); tail->type = NGX_HUNK_MEMORY|NGX_HUNK_LAST|NGX_HUNK_IN_MEMORY; tail->pos = error_tail; tail->last = error_tail + sizeof(error_tail); return ngx_http_output_filter(r, tail); }