comparison src/http/ngx_http_special_response.c @ 99:a059e1aa65d4

nginx-0.0.1-2003-06-02-19:24:30 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Jun 2003 15:24:30 +0000
parents c9b243802a17
children 6dfda4cf5200
comparison
equal deleted inserted replaced
98:c9b243802a17 99:a059e1aa65d4
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 4 #include <ngx_http.h>
5 #include <nginx.h> 5 #include <nginx.h>
6
7 #include <ngx_http.h>
8 #include <ngx_http_output_filter.h>
9 6
10 7
11 static char error_tail[] = 8 static char error_tail[] =
12 "<hr><center>" NGINX_VER "</center>" CRLF 9 "<hr><center>" NGINX_VER "</center>" CRLF
13 "</body>" CRLF 10 "</body>" CRLF
14 "</html>" CRLF 11 "</html>" CRLF
15 ; 12 ;
16 13
17 14
15 static char error_302_page[] =
16 "<html>" CRLF
17 "<head><title>302 Found</title></head>" CRLF
18 "<body bgcolor=\"white\">" CRLF
19 "<center><h1>302 Found</h1></center>" CRLF
20 ;
21
22
18 static char error_400_page[] = 23 static char error_400_page[] =
19 "<html>" CRLF 24 "<html>" CRLF
20 "<head><title>400 Bad Request</title></head>" CRLF 25 "<head><title>400 Bad Request</title></head>" CRLF
21 "<body bgcolor=\"white\">" CRLF 26 "<body bgcolor=\"white\">" CRLF
22 "<center><h1>400 Bad Request</h1></center>" CRLF 27 "<center><h1>400 Bad Request</h1></center>" CRLF
61 "<body bgcolor=\"white\">" CRLF 66 "<body bgcolor=\"white\">" CRLF
62 "<center><h1>414 Request-URI Too Large</h1></center>" CRLF 67 "<center><h1>414 Request-URI Too Large</h1></center>" CRLF
63 ; 68 ;
64 69
65 70
71 static char error_416_page[] =
72 "<html>" CRLF
73 "<head><title>416 Requested Range Not Satisfiable</title></head>" CRLF
74 "<body bgcolor=\"white\">" CRLF
75 "<center><h1>416 Requested Range Not Satisfiable</h1></center>" CRLF
76 ;
77
78
66 static char error_500_page[] = 79 static char error_500_page[] =
67 "<html>" CRLF 80 "<html>" CRLF
68 "<head><title>500 Internal Server Error</title></head>" CRLF 81 "<head><title>500 Internal Server Error</title></head>" CRLF
69 "<body bgcolor=\"white\">" CRLF 82 "<body bgcolor=\"white\">" CRLF
70 "<center><h1>500 Internal Server Error</h1></center>" CRLF 83 "<center><h1>500 Internal Server Error</h1></center>" CRLF
86 "<center><h1>504 Gateway Time-out</h1></center>" CRLF 99 "<center><h1>504 Gateway Time-out</h1></center>" CRLF
87 ; 100 ;
88 101
89 102
90 static ngx_str_t error_pages[] = { 103 static ngx_str_t error_pages[] = {
104 ngx_null_string, /* 300 */
91 ngx_null_string, /* 301 */ 105 ngx_null_string, /* 301 */
92 ngx_null_string, /* 302 */ 106 ngx_string(error_302_page),
93 ngx_null_string, /* 303 */ 107 ngx_null_string, /* 303 */
94 108
95 ngx_string(error_400_page), 109 ngx_string(error_400_page),
96 ngx_null_string, /* 401 */ 110 ngx_null_string, /* 401 */
97 ngx_null_string, /* 402 */ 111 ngx_null_string, /* 402 */
106 ngx_null_string, /* 411 */ 120 ngx_null_string, /* 411 */
107 ngx_null_string, /* 412 */ 121 ngx_null_string, /* 412 */
108 ngx_null_string, /* 413 */ 122 ngx_null_string, /* 413 */
109 ngx_string(error_414_page), 123 ngx_string(error_414_page),
110 ngx_null_string, /* 415 */ 124 ngx_null_string, /* 415 */
111 ngx_null_string, /* 416 */ 125 ngx_string(error_416_page),
112 126
113 ngx_string(error_500_page), 127 ngx_string(error_500_page),
114 ngx_null_string, /* 501 */ 128 ngx_null_string, /* 501 */
115 ngx_string(error_502_page), 129 ngx_string(error_502_page),
116 ngx_null_string, /* 503 */ 130 ngx_null_string, /* 503 */
118 }; 132 };
119 133
120 134
121 int ngx_http_special_response_handler(ngx_http_request_t *r, int error) 135 int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
122 { 136 {
123 int err, len; 137 int err;
124 ngx_hunk_t *message, *tail; 138 ngx_hunk_t *message, *tail;
125
126 len = 0;
127 139
128 r->headers_out.status = error; 140 r->headers_out.status = error;
129 141
130 if (error < NGX_HTTP_BAD_REQUEST) { 142 if (error < NGX_HTTP_BAD_REQUEST) {
131 /* 3XX */ 143 /* 3XX */
132 err = error - NGX_HTTP_MOVED_PERMANENTLY; 144 err = error - NGX_HTTP_MOVED_PERMANENTLY;
133 145
146 } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
147 /* 4XX */
148 err = error - NGX_HTTP_BAD_REQUEST + 4;
149
134 } else { 150 } else {
135 ngx_test_null(r->headers_out.content_type, 151 /* 5XX */
136 ngx_push_table(r->headers_out.headers), 152 err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 4 + 17;
137 NGX_HTTP_INTERNAL_SERVER_ERROR);
138
139 r->headers_out.content_type->key.len = 12;
140 r->headers_out.content_type->key.data = "Content-Type";
141 r->headers_out.content_type->value.len = 9;
142 r->headers_out.content_type->value.data = "text/html";
143
144 if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
145 /* 4XX */
146 err = error - NGX_HTTP_BAD_REQUEST + 3;
147
148 } else {
149 /* 5XX */
150 err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17;
151 }
152 } 153 }
153 154
154 if (r->keepalive != 0) { 155 if (r->keepalive != 0) {
155 switch (error) { 156 switch (error) {
156 case NGX_HTTP_BAD_REQUEST: 157 case NGX_HTTP_BAD_REQUEST:
167 case NGX_HTTP_INTERNAL_SERVER_ERROR: 168 case NGX_HTTP_INTERNAL_SERVER_ERROR:
168 r->lingering_close = 0; 169 r->lingering_close = 0;
169 } 170 }
170 } 171 }
171 172
172 if (error_pages[err].len == 0) { 173 if (error_pages[err].len) {
174 r->headers_out.content_length = error_pages[err].len
175 + sizeof(error_tail);
176
177 ngx_test_null(r->headers_out.content_type,
178 ngx_push_table(r->headers_out.headers),
179 NGX_HTTP_INTERNAL_SERVER_ERROR);
180
181 r->headers_out.content_type->key.len = 12;
182 r->headers_out.content_type->key.data = "Content-Type";
183 r->headers_out.content_type->value.len = 9;
184 r->headers_out.content_type->value.data = "text/html";
185
186 } else {
173 r->headers_out.content_length = -1; 187 r->headers_out.content_length = -1;
174 } else {
175 r->headers_out.content_length = error_pages[err].len
176 + len + sizeof(error_tail);
177 } 188 }
178 189
179 if (ngx_http_send_header(r) == NGX_ERROR) { 190 if (ngx_http_send_header(r) == NGX_ERROR) {
180 return NGX_ERROR; 191 return NGX_ERROR;
181 } 192 }