0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10 #include <nginx.h>
|
|
11
|
|
12
|
344
|
13 static ngx_int_t ngx_http_send_error_page(ngx_http_request_t *r,
|
|
14 ngx_http_err_page_t *err_page);
|
|
15 static ngx_int_t ngx_http_send_special_response(ngx_http_request_t *r,
|
|
16 ngx_http_core_loc_conf_t *clcf, ngx_uint_t err);
|
|
17 static ngx_int_t ngx_http_send_refresh(ngx_http_request_t *r);
|
|
18
|
|
19
|
|
20 static u_char ngx_http_error_full_tail[] =
|
342
|
21 "<hr><center>" NGINX_VER "</center>" CRLF
|
|
22 "</body>" CRLF
|
|
23 "</html>" CRLF
|
|
24 ;
|
|
25
|
|
26
|
344
|
27 static u_char ngx_http_error_tail[] =
|
342
|
28 "<hr><center>nginx</center>" CRLF
|
0
|
29 "</body>" CRLF
|
|
30 "</html>" CRLF
|
|
31 ;
|
|
32
|
|
33
|
50
|
34 static u_char ngx_http_msie_stub[] =
|
0
|
35 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
36 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
37 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
38 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
39 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
40 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
|
41 ;
|
|
42
|
|
43
|
228
|
44 static u_char ngx_http_msie_refresh_head[] =
|
|
45 "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=";
|
|
46
|
|
47
|
|
48 static u_char ngx_http_msie_refresh_tail[] =
|
|
49 "\"></head><body></body></html>" CRLF;
|
|
50
|
|
51
|
344
|
52 static char ngx_http_error_301_page[] =
|
0
|
53 "<html>" CRLF
|
|
54 "<head><title>301 Moved Permanently</title></head>" CRLF
|
|
55 "<body bgcolor=\"white\">" CRLF
|
|
56 "<center><h1>301 Moved Permanently</h1></center>" CRLF
|
|
57 ;
|
|
58
|
|
59
|
344
|
60 static char ngx_http_error_302_page[] =
|
0
|
61 "<html>" CRLF
|
|
62 "<head><title>302 Found</title></head>" CRLF
|
|
63 "<body bgcolor=\"white\">" CRLF
|
|
64 "<center><h1>302 Found</h1></center>" CRLF
|
|
65 ;
|
|
66
|
|
67
|
344
|
68 static char ngx_http_error_400_page[] =
|
0
|
69 "<html>" CRLF
|
|
70 "<head><title>400 Bad Request</title></head>" CRLF
|
|
71 "<body bgcolor=\"white\">" CRLF
|
|
72 "<center><h1>400 Bad Request</h1></center>" CRLF
|
|
73 ;
|
|
74
|
|
75
|
344
|
76 static char ngx_http_error_401_page[] =
|
48
|
77 "<html>" CRLF
|
52
|
78 "<head><title>401 Authorization Required</title></head>" CRLF
|
48
|
79 "<body bgcolor=\"white\">" CRLF
|
52
|
80 "<center><h1>401 Authorization Required</h1></center>" CRLF
|
48
|
81 ;
|
|
82
|
|
83
|
344
|
84 static char ngx_http_error_402_page[] =
|
48
|
85 "<html>" CRLF
|
|
86 "<head><title>402 Payment Required</title></head>" CRLF
|
|
87 "<body bgcolor=\"white\">" CRLF
|
|
88 "<center><h1>402 Payment Required</h1></center>" CRLF
|
|
89 ;
|
|
90
|
|
91
|
344
|
92 static char ngx_http_error_403_page[] =
|
0
|
93 "<html>" CRLF
|
|
94 "<head><title>403 Forbidden</title></head>" CRLF
|
|
95 "<body bgcolor=\"white\">" CRLF
|
|
96 "<center><h1>403 Forbidden</h1></center>" CRLF
|
|
97 ;
|
|
98
|
|
99
|
344
|
100 static char ngx_http_error_404_page[] =
|
0
|
101 "<html>" CRLF
|
|
102 "<head><title>404 Not Found</title></head>" CRLF
|
|
103 "<body bgcolor=\"white\">" CRLF
|
|
104 "<center><h1>404 Not Found</h1></center>" CRLF
|
|
105 ;
|
|
106
|
|
107
|
344
|
108 static char ngx_http_error_405_page[] =
|
0
|
109 "<html>" CRLF
|
|
110 "<head><title>405 Not Allowed</title></head>" CRLF
|
|
111 "<body bgcolor=\"white\">" CRLF
|
|
112 "<center><h1>405 Not Allowed</h1></center>" CRLF
|
|
113 ;
|
|
114
|
|
115
|
344
|
116 static char ngx_http_error_406_page[] =
|
48
|
117 "<html>" CRLF
|
|
118 "<head><title>406 Not Acceptable</title></head>" CRLF
|
|
119 "<body bgcolor=\"white\">" CRLF
|
|
120 "<center><h1>406 Not Acceptable</h1></center>" CRLF
|
|
121 ;
|
|
122
|
|
123
|
344
|
124 static char ngx_http_error_408_page[] =
|
0
|
125 "<html>" CRLF
|
|
126 "<head><title>408 Request Time-out</title></head>" CRLF
|
|
127 "<body bgcolor=\"white\">" CRLF
|
|
128 "<center><h1>408 Request Time-out</h1></center>" CRLF
|
|
129 ;
|
|
130
|
|
131
|
344
|
132 static char ngx_http_error_409_page[] =
|
186
|
133 "<html>" CRLF
|
|
134 "<head><title>409 Conflict</title></head>" CRLF
|
|
135 "<body bgcolor=\"white\">" CRLF
|
|
136 "<center><h1>409 Conflict</h1></center>" CRLF
|
|
137 ;
|
|
138
|
|
139
|
344
|
140 static char ngx_http_error_410_page[] =
|
48
|
141 "<html>" CRLF
|
|
142 "<head><title>410 Gone</title></head>" CRLF
|
|
143 "<body bgcolor=\"white\">" CRLF
|
|
144 "<center><h1>410 Gone</h1></center>" CRLF
|
|
145 ;
|
|
146
|
|
147
|
344
|
148 static char ngx_http_error_411_page[] =
|
130
|
149 "<html>" CRLF
|
|
150 "<head><title>411 Length Required</title></head>" CRLF
|
|
151 "<body bgcolor=\"white\">" CRLF
|
|
152 "<center><h1>411 Length Required</h1></center>" CRLF
|
|
153 ;
|
|
154
|
|
155
|
344
|
156 static char ngx_http_error_412_page[] =
|
276
|
157 "<html>" CRLF
|
|
158 "<head><title>412 Precondition Failed</title></head>" CRLF
|
|
159 "<body bgcolor=\"white\">" CRLF
|
|
160 "<center><h1>412 Precondition Failed</h1></center>" CRLF
|
|
161 ;
|
|
162
|
|
163
|
344
|
164 static char ngx_http_error_413_page[] =
|
0
|
165 "<html>" CRLF
|
|
166 "<head><title>413 Request Entity Too Large</title></head>" CRLF
|
|
167 "<body bgcolor=\"white\">" CRLF
|
|
168 "<center><h1>413 Request Entity Too Large</h1></center>" CRLF
|
|
169 ;
|
|
170
|
|
171
|
344
|
172 static char ngx_http_error_414_page[] =
|
0
|
173 "<html>" CRLF
|
|
174 "<head><title>414 Request-URI Too Large</title></head>" CRLF
|
|
175 "<body bgcolor=\"white\">" CRLF
|
|
176 "<center><h1>414 Request-URI Too Large</h1></center>" CRLF
|
|
177 ;
|
|
178
|
|
179
|
344
|
180 static char ngx_http_error_415_page[] =
|
186
|
181 "<html>" CRLF
|
|
182 "<head><title>415 Unsupported Media Type</title></head>" CRLF
|
|
183 "<body bgcolor=\"white\">" CRLF
|
|
184 "<center><h1>415 Unsupported Media Type</h1></center>" CRLF
|
|
185 ;
|
|
186
|
|
187
|
344
|
188 static char ngx_http_error_416_page[] =
|
0
|
189 "<html>" CRLF
|
|
190 "<head><title>416 Requested Range Not Satisfiable</title></head>" CRLF
|
|
191 "<body bgcolor=\"white\">" CRLF
|
|
192 "<center><h1>416 Requested Range Not Satisfiable</h1></center>" CRLF
|
|
193 ;
|
|
194
|
|
195
|
344
|
196 static char ngx_http_error_495_page[] =
|
196
|
197 "<html>" CRLF
|
|
198 "<head><title>400 The SSL certificate error</title></head>"
|
|
199 CRLF
|
|
200 "<body bgcolor=\"white\">" CRLF
|
|
201 "<center><h1>400 Bad Request</h1></center>" CRLF
|
|
202 "<center>The SSL certificate error</center>" CRLF
|
|
203 ;
|
|
204
|
|
205
|
344
|
206 static char ngx_http_error_496_page[] =
|
196
|
207 "<html>" CRLF
|
|
208 "<head><title>400 No required SSL certificate was sent</title></head>"
|
|
209 CRLF
|
|
210 "<body bgcolor=\"white\">" CRLF
|
|
211 "<center><h1>400 Bad Request</h1></center>" CRLF
|
|
212 "<center>No required SSL certificate was sent</center>" CRLF
|
|
213 ;
|
|
214
|
|
215
|
344
|
216 static char ngx_http_error_497_page[] =
|
0
|
217 "<html>" CRLF
|
|
218 "<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>"
|
|
219 CRLF
|
|
220 "<body bgcolor=\"white\">" CRLF
|
|
221 "<center><h1>400 Bad Request</h1></center>" CRLF
|
|
222 "<center>The plain HTTP request was sent to HTTPS port</center>" CRLF
|
|
223 ;
|
|
224
|
|
225
|
344
|
226 static char ngx_http_error_500_page[] =
|
0
|
227 "<html>" CRLF
|
|
228 "<head><title>500 Internal Server Error</title></head>" CRLF
|
|
229 "<body bgcolor=\"white\">" CRLF
|
|
230 "<center><h1>500 Internal Server Error</h1></center>" CRLF
|
|
231 ;
|
|
232
|
|
233
|
344
|
234 static char ngx_http_error_501_page[] =
|
0
|
235 "<html>" CRLF
|
|
236 "<head><title>501 Method Not Implemented</title></head>" CRLF
|
|
237 "<body bgcolor=\"white\">" CRLF
|
84
|
238 "<center><h1>501 Method Not Implemented</h1></center>" CRLF
|
0
|
239 ;
|
|
240
|
|
241
|
344
|
242 static char ngx_http_error_502_page[] =
|
0
|
243 "<html>" CRLF
|
|
244 "<head><title>502 Bad Gateway</title></head>" CRLF
|
|
245 "<body bgcolor=\"white\">" CRLF
|
|
246 "<center><h1>502 Bad Gateway</h1></center>" CRLF
|
|
247 ;
|
|
248
|
|
249
|
344
|
250 static char ngx_http_error_503_page[] =
|
0
|
251 "<html>" CRLF
|
|
252 "<head><title>503 Service Temporarily Unavailable</title></head>" CRLF
|
|
253 "<body bgcolor=\"white\">" CRLF
|
|
254 "<center><h1>503 Service Temporarily Unavailable</h1></center>" CRLF
|
|
255 ;
|
|
256
|
|
257
|
344
|
258 static char ngx_http_error_504_page[] =
|
0
|
259 "<html>" CRLF
|
|
260 "<head><title>504 Gateway Time-out</title></head>" CRLF
|
|
261 "<body bgcolor=\"white\">" CRLF
|
|
262 "<center><h1>504 Gateway Time-out</h1></center>" CRLF
|
|
263 ;
|
|
264
|
|
265
|
344
|
266 static char ngx_http_error_507_page[] =
|
186
|
267 "<html>" CRLF
|
|
268 "<head><title>507 Insufficient Storage</title></head>" CRLF
|
|
269 "<body bgcolor=\"white\">" CRLF
|
|
270 "<center><h1>507 Insufficient Storage</h1></center>" CRLF
|
|
271 ;
|
|
272
|
|
273
|
344
|
274 static ngx_str_t ngx_http_error_pages[] = {
|
48
|
275
|
344
|
276 ngx_null_string, /* 201, 204 */
|
60
|
277
|
|
278 #define NGX_HTTP_LEVEL_200 1
|
|
279
|
344
|
280 /* ngx_null_string, */ /* 300 */
|
|
281 ngx_string(ngx_http_error_301_page),
|
|
282 ngx_string(ngx_http_error_302_page),
|
|
283 ngx_null_string, /* 303 */
|
0
|
284
|
48
|
285 #define NGX_HTTP_LEVEL_300 3
|
|
286
|
344
|
287 ngx_string(ngx_http_error_400_page),
|
|
288 ngx_string(ngx_http_error_401_page),
|
|
289 ngx_string(ngx_http_error_402_page),
|
|
290 ngx_string(ngx_http_error_403_page),
|
|
291 ngx_string(ngx_http_error_404_page),
|
|
292 ngx_string(ngx_http_error_405_page),
|
|
293 ngx_string(ngx_http_error_406_page),
|
|
294 ngx_null_string, /* 407 */
|
|
295 ngx_string(ngx_http_error_408_page),
|
|
296 ngx_string(ngx_http_error_409_page),
|
|
297 ngx_string(ngx_http_error_410_page),
|
|
298 ngx_string(ngx_http_error_411_page),
|
|
299 ngx_string(ngx_http_error_412_page),
|
|
300 ngx_string(ngx_http_error_413_page),
|
|
301 ngx_string(ngx_http_error_414_page),
|
|
302 ngx_string(ngx_http_error_415_page),
|
|
303 ngx_string(ngx_http_error_416_page),
|
0
|
304
|
48
|
305 #define NGX_HTTP_LEVEL_400 17
|
|
306
|
344
|
307 ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
|
|
308 ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
|
|
309 ngx_string(ngx_http_error_497_page), /* 497, http to https */
|
354
|
310 ngx_string(ngx_http_error_404_page), /* 498, canceled */
|
344
|
311 ngx_null_string, /* 499, client has closed connection */
|
0
|
312
|
344
|
313 ngx_string(ngx_http_error_500_page),
|
|
314 ngx_string(ngx_http_error_501_page),
|
|
315 ngx_string(ngx_http_error_502_page),
|
|
316 ngx_string(ngx_http_error_503_page),
|
|
317 ngx_string(ngx_http_error_504_page),
|
|
318 ngx_null_string, /* 505 */
|
|
319 ngx_null_string, /* 506 */
|
|
320 ngx_string(ngx_http_error_507_page)
|
0
|
321 };
|
|
322
|
|
323
|
236
|
324 static ngx_str_t ngx_http_get_name = { 3, (u_char *) "GET " };
|
|
325
|
|
326
|
36
|
327 ngx_int_t
|
|
328 ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
|
0
|
329 {
|
344
|
330 ngx_uint_t i, err;
|
0
|
331 ngx_http_err_page_t *err_page;
|
|
332 ngx_http_core_loc_conf_t *clcf;
|
|
333
|
380
|
334 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
335 "http special response: %d, \"%V?%V\"",
|
|
336 error, &r->uri, &r->args);
|
76
|
337
|
226
|
338 r->err_status = error;
|
0
|
339
|
378
|
340 if (r->keepalive) {
|
0
|
341 switch (error) {
|
|
342 case NGX_HTTP_BAD_REQUEST:
|
|
343 case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:
|
|
344 case NGX_HTTP_REQUEST_URI_TOO_LARGE:
|
|
345 case NGX_HTTP_TO_HTTPS:
|
196
|
346 case NGX_HTTPS_CERT_ERROR:
|
|
347 case NGX_HTTPS_NO_CERT:
|
0
|
348 case NGX_HTTP_INTERNAL_SERVER_ERROR:
|
|
349 r->keepalive = 0;
|
|
350 }
|
|
351 }
|
|
352
|
|
353 if (r->lingering_close == 1) {
|
|
354 switch (error) {
|
|
355 case NGX_HTTP_BAD_REQUEST:
|
|
356 case NGX_HTTP_TO_HTTPS:
|
196
|
357 case NGX_HTTPS_CERT_ERROR:
|
|
358 case NGX_HTTPS_NO_CERT:
|
0
|
359 r->lingering_close = 0;
|
|
360 }
|
|
361 }
|
|
362
|
224
|
363 r->headers_out.content_type.len = 0;
|
|
364
|
0
|
365 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
366
|
400
|
367 if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {
|
228
|
368
|
|
369 if (clcf->recursive_error_pages == 0) {
|
|
370 r->error_page = 1;
|
|
371 }
|
26
|
372
|
0
|
373 err_page = clcf->error_pages->elts;
|
26
|
374
|
0
|
375 for (i = 0; i < clcf->error_pages->nelts; i++) {
|
|
376 if (err_page[i].status == error) {
|
344
|
377 return ngx_http_send_error_page(r, &err_page[i]);
|
0
|
378 }
|
|
379 }
|
|
380 }
|
|
381
|
447
|
382 r->expect_tested = 1;
|
|
383
|
406
|
384 if (ngx_http_discard_request_body(r) != NGX_OK) {
|
|
385 error = NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
386 }
|
|
387
|
344
|
388 if (clcf->msie_refresh
|
|
389 && r->headers_in.msie
|
|
390 && (error == NGX_HTTP_MOVED_PERMANENTLY
|
|
391 || error == NGX_HTTP_MOVED_TEMPORARILY))
|
|
392 {
|
|
393 return ngx_http_send_refresh(r);
|
|
394 }
|
|
395
|
182
|
396 if (error == NGX_HTTP_CREATED) {
|
|
397 /* 201 */
|
|
398 err = 0;
|
186
|
399 r->header_only = 1;
|
182
|
400
|
|
401 } else if (error == NGX_HTTP_NO_CONTENT) {
|
60
|
402 /* 204 */
|
|
403 err = 0;
|
|
404
|
|
405 } else if (error < NGX_HTTP_BAD_REQUEST) {
|
0
|
406 /* 3XX */
|
62
|
407 err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200;
|
0
|
408
|
136
|
409 } else if (error < NGX_HTTP_OWN_CODES) {
|
0
|
410 /* 4XX */
|
60
|
411 err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_LEVEL_200
|
|
412 + NGX_HTTP_LEVEL_300;
|
0
|
413
|
|
414 } else {
|
|
415 /* 49X, 5XX */
|
136
|
416 err = error - NGX_HTTP_OWN_CODES + NGX_HTTP_LEVEL_200
|
60
|
417 + NGX_HTTP_LEVEL_300
|
48
|
418 + NGX_HTTP_LEVEL_400;
|
0
|
419 switch (error) {
|
|
420 case NGX_HTTP_TO_HTTPS:
|
196
|
421 case NGX_HTTPS_CERT_ERROR:
|
|
422 case NGX_HTTPS_NO_CERT:
|
228
|
423 r->err_status = NGX_HTTP_BAD_REQUEST;
|
0
|
424 break;
|
|
425 }
|
|
426 }
|
|
427
|
344
|
428 return ngx_http_send_special_response(r, clcf, err);
|
|
429 }
|
|
430
|
|
431
|
|
432 static ngx_int_t
|
|
433 ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
|
|
434 {
|
447
|
435 ngx_int_t overwrite;
|
473
|
436 ngx_str_t uri, args;
|
344
|
437 ngx_table_elt_t *location;
|
|
438 ngx_http_core_loc_conf_t *clcf;
|
|
439
|
447
|
440 overwrite = err_page->overwrite;
|
|
441
|
|
442 if (overwrite && overwrite != NGX_HTTP_OK) {
|
|
443 r->expect_tested = 1;
|
|
444 }
|
|
445
|
|
446 r->err_status = overwrite;
|
344
|
447
|
|
448 r->zero_in_uri = 0;
|
|
449
|
473
|
450 if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {
|
|
451 return NGX_ERROR;
|
|
452 }
|
344
|
453
|
473
|
454 if (err_page->value.lengths) {
|
|
455 ngx_http_split_args(r, &uri, &args);
|
344
|
456
|
|
457 } else {
|
473
|
458 args = err_page->args;
|
344
|
459 }
|
|
460
|
473
|
461 if (uri.data[0] == '/') {
|
366
|
462
|
406
|
463 if (r->method != NGX_HTTP_HEAD) {
|
|
464 r->method = NGX_HTTP_GET;
|
|
465 r->method_name = ngx_http_get_name;
|
|
466 }
|
366
|
467
|
473
|
468 return ngx_http_internal_redirect(r, &uri, &args);
|
344
|
469 }
|
|
470
|
473
|
471 if (uri.data[0] == '@') {
|
|
472 return ngx_http_named_location(r, &uri);
|
344
|
473 }
|
|
474
|
|
475 location = ngx_list_push(&r->headers_out.headers);
|
|
476
|
|
477 if (location == NULL) {
|
|
478 return NGX_ERROR;
|
|
479 }
|
|
480
|
|
481 r->err_status = NGX_HTTP_MOVED_TEMPORARILY;
|
|
482
|
|
483 location->hash = 1;
|
|
484 location->key.len = sizeof("Location") - 1;
|
|
485 location->key.data = (u_char *) "Location";
|
473
|
486 location->value = uri;
|
344
|
487
|
|
488 r->headers_out.location = location;
|
|
489
|
|
490 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
491
|
|
492 if (clcf->msie_refresh && r->headers_in.msie) {
|
|
493 return ngx_http_send_refresh(r);
|
|
494 }
|
|
495
|
|
496 return ngx_http_send_special_response(r, clcf, NGX_HTTP_MOVED_TEMPORARILY
|
|
497 - NGX_HTTP_MOVED_PERMANENTLY
|
|
498 + NGX_HTTP_LEVEL_200);
|
|
499 }
|
|
500
|
|
501
|
|
502 static ngx_int_t
|
|
503 ngx_http_send_special_response(ngx_http_request_t *r,
|
|
504 ngx_http_core_loc_conf_t *clcf, ngx_uint_t err)
|
|
505 {
|
|
506 u_char *tail;
|
|
507 size_t len;
|
|
508 ngx_int_t rc;
|
|
509 ngx_buf_t *b;
|
|
510 ngx_uint_t msie_padding;
|
|
511 ngx_chain_t out[3];
|
|
512
|
|
513 if (clcf->server_tokens) {
|
|
514 len = sizeof(ngx_http_error_full_tail) - 1;
|
|
515 tail = ngx_http_error_full_tail;
|
|
516
|
|
517 } else {
|
|
518 len = sizeof(ngx_http_error_tail) - 1;
|
|
519 tail = ngx_http_error_tail;
|
|
520 }
|
|
521
|
0
|
522 msie_padding = 0;
|
|
523
|
238
|
524 if (!r->zero_body) {
|
344
|
525 if (ngx_http_error_pages[err].len) {
|
|
526 r->headers_out.content_length_n = ngx_http_error_pages[err].len
|
|
527 + len;
|
238
|
528 if (clcf->msie_padding
|
|
529 && r->headers_in.msie
|
|
530 && r->http_version >= NGX_HTTP_VERSION_10
|
344
|
531 && err >= NGX_HTTP_LEVEL_300)
|
238
|
532 {
|
|
533 r->headers_out.content_length_n +=
|
|
534 sizeof(ngx_http_msie_stub) - 1;
|
|
535 msie_padding = 1;
|
|
536 }
|
|
537
|
344
|
538 r->headers_out.content_type_len = sizeof("text/html") - 1;
|
238
|
539 r->headers_out.content_type.len = sizeof("text/html") - 1;
|
|
540 r->headers_out.content_type.data = (u_char *) "text/html";
|
|
541
|
|
542 } else {
|
|
543 r->headers_out.content_length_n = -1;
|
0
|
544 }
|
|
545
|
|
546 } else {
|
238
|
547 r->headers_out.content_length_n = 0;
|
|
548 err = 0;
|
0
|
549 }
|
|
550
|
|
551 if (r->headers_out.content_length) {
|
58
|
552 r->headers_out.content_length->hash = 0;
|
0
|
553 r->headers_out.content_length = NULL;
|
|
554 }
|
|
555
|
344
|
556 ngx_http_clear_accept_ranges(r);
|
|
557 ngx_http_clear_last_modified(r);
|
|
558
|
|
559 rc = ngx_http_send_header(r);
|
|
560
|
|
561 if (rc == NGX_ERROR || r->header_only) {
|
|
562 return rc;
|
|
563 }
|
|
564
|
|
565 if (ngx_http_error_pages[err].len == 0) {
|
|
566 return NGX_OK;
|
|
567 }
|
|
568
|
|
569 b = ngx_calloc_buf(r->pool);
|
|
570 if (b == NULL) {
|
|
571 return NGX_ERROR;
|
|
572 }
|
|
573
|
|
574 b->memory = 1;
|
|
575 b->pos = ngx_http_error_pages[err].data;
|
|
576 b->last = ngx_http_error_pages[err].data + ngx_http_error_pages[err].len;
|
320
|
577
|
344
|
578 out[0].buf = b;
|
|
579 out[0].next = &out[1];
|
|
580
|
|
581 b = ngx_calloc_buf(r->pool);
|
|
582 if (b == NULL) {
|
|
583 return NGX_ERROR;
|
|
584 }
|
|
585
|
|
586 b->memory = 1;
|
|
587
|
|
588 b->pos = tail;
|
|
589 b->last = tail + len;
|
320
|
590
|
344
|
591 out[1].buf = b;
|
378
|
592 out[1].next = NULL;
|
344
|
593
|
|
594 if (msie_padding) {
|
|
595 b = ngx_calloc_buf(r->pool);
|
|
596 if (b == NULL) {
|
|
597 return NGX_ERROR;
|
|
598 }
|
|
599
|
|
600 b->memory = 1;
|
|
601 b->pos = ngx_http_msie_stub;
|
|
602 b->last = ngx_http_msie_stub + sizeof(ngx_http_msie_stub) - 1;
|
320
|
603
|
344
|
604 out[1].next = &out[2];
|
|
605 out[2].buf = b;
|
378
|
606 out[2].next = NULL;
|
344
|
607 }
|
|
608
|
|
609 if (r == r->main) {
|
|
610 b->last_buf = 1;
|
|
611 }
|
|
612
|
|
613 b->last_in_chain = 1;
|
|
614
|
|
615 return ngx_http_output_filter(r, &out[0]);
|
|
616 }
|
|
617
|
228
|
618
|
344
|
619 static ngx_int_t
|
|
620 ngx_http_send_refresh(ngx_http_request_t *r)
|
|
621 {
|
|
622 u_char *p, *location;
|
|
623 size_t len, size;
|
|
624 uintptr_t escape;
|
|
625 ngx_int_t rc;
|
|
626 ngx_buf_t *b;
|
|
627 ngx_chain_t out;
|
|
628
|
|
629 len = r->headers_out.location->value.len;
|
|
630 location = r->headers_out.location->value.data;
|
|
631
|
|
632 escape = 2 * ngx_escape_uri(NULL, location, len, NGX_ESCAPE_REFRESH);
|
320
|
633
|
344
|
634 size = sizeof(ngx_http_msie_refresh_head) - 1
|
|
635 + escape + len
|
|
636 + sizeof(ngx_http_msie_refresh_tail) - 1;
|
|
637
|
|
638 r->err_status = NGX_HTTP_OK;
|
|
639
|
|
640 r->headers_out.content_type_len = sizeof("text/html") - 1;
|
|
641 r->headers_out.content_type.len = sizeof("text/html") - 1;
|
|
642 r->headers_out.content_type.data = (u_char *) "text/html";
|
|
643
|
|
644 r->headers_out.location->hash = 0;
|
|
645 r->headers_out.location = NULL;
|
|
646
|
|
647 r->headers_out.content_length_n = size;
|
|
648
|
|
649 if (r->headers_out.content_length) {
|
|
650 r->headers_out.content_length->hash = 0;
|
|
651 r->headers_out.content_length = NULL;
|
228
|
652 }
|
|
653
|
126
|
654 ngx_http_clear_accept_ranges(r);
|
|
655 ngx_http_clear_last_modified(r);
|
|
656
|
0
|
657 rc = ngx_http_send_header(r);
|
|
658
|
|
659 if (rc == NGX_ERROR || r->header_only) {
|
|
660 return rc;
|
|
661 }
|
|
662
|
344
|
663 b = ngx_create_temp_buf(r->pool, size);
|
|
664 if (b == NULL) {
|
|
665 return NGX_ERROR;
|
|
666 }
|
342
|
667
|
344
|
668 p = ngx_cpymem(b->pos, ngx_http_msie_refresh_head,
|
|
669 sizeof(ngx_http_msie_refresh_head) - 1);
|
228
|
670
|
344
|
671 if (escape == 0) {
|
|
672 p = ngx_cpymem(p, location, len);
|
228
|
673
|
|
674 } else {
|
344
|
675 p = (u_char *) ngx_escape_uri(p, location, len, NGX_ESCAPE_REFRESH);
|
0
|
676 }
|
|
677
|
344
|
678 b->last = ngx_cpymem(p, ngx_http_msie_refresh_tail,
|
|
679 sizeof(ngx_http_msie_refresh_tail) - 1);
|
58
|
680
|
344
|
681 b->last_buf = 1;
|
58
|
682 b->last_in_chain = 1;
|
0
|
683
|
344
|
684 out.buf = b;
|
|
685 out.next = NULL;
|
50
|
686
|
344
|
687 return ngx_http_output_filter(r, &out);
|
0
|
688 }
|