Mercurial > hg > nginx
comparison src/http/ngx_http_special_response.c @ 4513:2dfa4d76e4c5 stable-1.0
Merge of r4491, r4492:
*) Renamed constants and fixed off-by-one error in "msie_padding on"
handling.
*) Added support for the 307 Temporary Redirect.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 05 Mar 2012 13:03:39 +0000 |
parents | 4919fb357a5d |
children |
comparison
equal
deleted
inserted
replaced
4512:cbed47593ce0 | 4513:2dfa4d76e4c5 |
---|---|
72 "<body bgcolor=\"white\">" CRLF | 72 "<body bgcolor=\"white\">" CRLF |
73 "<center><h1>303 See Other</h1></center>" CRLF | 73 "<center><h1>303 See Other</h1></center>" CRLF |
74 ; | 74 ; |
75 | 75 |
76 | 76 |
77 static char ngx_http_error_307_page[] = | |
78 "<html>" CRLF | |
79 "<head><title>307 Temporary Redirect</title></head>" CRLF | |
80 "<body bgcolor=\"white\">" CRLF | |
81 "<center><h1>307 Temporary Redirect</h1></center>" CRLF | |
82 ; | |
83 | |
84 | |
77 static char ngx_http_error_400_page[] = | 85 static char ngx_http_error_400_page[] = |
78 "<html>" CRLF | 86 "<html>" CRLF |
79 "<head><title>400 Bad Request</title></head>" CRLF | 87 "<head><title>400 Bad Request</title></head>" CRLF |
80 "<body bgcolor=\"white\">" CRLF | 88 "<body bgcolor=\"white\">" CRLF |
81 "<center><h1>400 Bad Request</h1></center>" CRLF | 89 "<center><h1>400 Bad Request</h1></center>" CRLF |
292 | 300 |
293 static ngx_str_t ngx_http_error_pages[] = { | 301 static ngx_str_t ngx_http_error_pages[] = { |
294 | 302 |
295 ngx_null_string, /* 201, 204 */ | 303 ngx_null_string, /* 201, 204 */ |
296 | 304 |
297 #define NGX_HTTP_LAST_LEVEL_200 202 | 305 #define NGX_HTTP_LAST_2XX 202 |
298 #define NGX_HTTP_LEVEL_200 (NGX_HTTP_LAST_LEVEL_200 - 201) | 306 #define NGX_HTTP_OFF_3XX (NGX_HTTP_LAST_2XX - 201) |
299 | 307 |
300 /* ngx_null_string, */ /* 300 */ | 308 /* ngx_null_string, */ /* 300 */ |
301 ngx_string(ngx_http_error_301_page), | 309 ngx_string(ngx_http_error_301_page), |
302 ngx_string(ngx_http_error_302_page), | 310 ngx_string(ngx_http_error_302_page), |
303 ngx_string(ngx_http_error_303_page), | 311 ngx_string(ngx_http_error_303_page), |
304 | 312 ngx_null_string, /* 304 */ |
305 #define NGX_HTTP_LAST_LEVEL_300 304 | 313 ngx_null_string, /* 305 */ |
306 #define NGX_HTTP_LEVEL_300 (NGX_HTTP_LAST_LEVEL_300 - 301) | 314 ngx_null_string, /* 306 */ |
315 ngx_string(ngx_http_error_307_page), | |
316 | |
317 #define NGX_HTTP_LAST_3XX 308 | |
318 #define NGX_HTTP_OFF_4XX (NGX_HTTP_LAST_3XX - 301 + NGX_HTTP_OFF_3XX) | |
307 | 319 |
308 ngx_string(ngx_http_error_400_page), | 320 ngx_string(ngx_http_error_400_page), |
309 ngx_string(ngx_http_error_401_page), | 321 ngx_string(ngx_http_error_401_page), |
310 ngx_string(ngx_http_error_402_page), | 322 ngx_string(ngx_http_error_402_page), |
311 ngx_string(ngx_http_error_403_page), | 323 ngx_string(ngx_http_error_403_page), |
321 ngx_string(ngx_http_error_413_page), | 333 ngx_string(ngx_http_error_413_page), |
322 ngx_string(ngx_http_error_414_page), | 334 ngx_string(ngx_http_error_414_page), |
323 ngx_string(ngx_http_error_415_page), | 335 ngx_string(ngx_http_error_415_page), |
324 ngx_string(ngx_http_error_416_page), | 336 ngx_string(ngx_http_error_416_page), |
325 | 337 |
326 #define NGX_HTTP_LAST_LEVEL_400 417 | 338 #define NGX_HTTP_LAST_4XX 417 |
327 #define NGX_HTTP_LEVEL_400 (NGX_HTTP_LAST_LEVEL_400 - 400) | 339 #define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX) |
328 | 340 |
329 ngx_string(ngx_http_error_494_page), /* 494, request header too large */ | 341 ngx_string(ngx_http_error_494_page), /* 494, request header too large */ |
330 ngx_string(ngx_http_error_495_page), /* 495, https certificate error */ | 342 ngx_string(ngx_http_error_495_page), /* 495, https certificate error */ |
331 ngx_string(ngx_http_error_496_page), /* 496, https no certificate */ | 343 ngx_string(ngx_http_error_496_page), /* 496, https no certificate */ |
332 ngx_string(ngx_http_error_497_page), /* 497, http to https */ | 344 ngx_string(ngx_http_error_497_page), /* 497, http to https */ |
340 ngx_string(ngx_http_error_504_page), | 352 ngx_string(ngx_http_error_504_page), |
341 ngx_null_string, /* 505 */ | 353 ngx_null_string, /* 505 */ |
342 ngx_null_string, /* 506 */ | 354 ngx_null_string, /* 506 */ |
343 ngx_string(ngx_http_error_507_page) | 355 ngx_string(ngx_http_error_507_page) |
344 | 356 |
345 #define NGX_HTTP_LAST_LEVEL_500 508 | 357 #define NGX_HTTP_LAST_5XX 508 |
346 | 358 |
347 }; | 359 }; |
348 | 360 |
349 | 361 |
350 static ngx_str_t ngx_http_get_name = { 3, (u_char *) "GET " }; | 362 static ngx_str_t ngx_http_get_name = { 3, (u_char *) "GET " }; |
426 } else if (error == NGX_HTTP_NO_CONTENT) { | 438 } else if (error == NGX_HTTP_NO_CONTENT) { |
427 /* 204 */ | 439 /* 204 */ |
428 err = 0; | 440 err = 0; |
429 | 441 |
430 } else if (error >= NGX_HTTP_MOVED_PERMANENTLY | 442 } else if (error >= NGX_HTTP_MOVED_PERMANENTLY |
431 && error < NGX_HTTP_LAST_LEVEL_300) | 443 && error < NGX_HTTP_LAST_3XX) |
432 { | 444 { |
433 /* 3XX */ | 445 /* 3XX */ |
434 err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200; | 446 err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX; |
435 | 447 |
436 } else if (error >= NGX_HTTP_BAD_REQUEST | 448 } else if (error >= NGX_HTTP_BAD_REQUEST |
437 && error < NGX_HTTP_LAST_LEVEL_400) | 449 && error < NGX_HTTP_LAST_4XX) |
438 { | 450 { |
439 /* 4XX */ | 451 /* 4XX */ |
440 err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_LEVEL_200 | 452 err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX; |
441 + NGX_HTTP_LEVEL_300; | |
442 | 453 |
443 } else if (error >= NGX_HTTP_NGINX_CODES | 454 } else if (error >= NGX_HTTP_NGINX_CODES |
444 && error < NGX_HTTP_LAST_LEVEL_500) | 455 && error < NGX_HTTP_LAST_5XX) |
445 { | 456 { |
446 /* 49X, 5XX */ | 457 /* 49X, 5XX */ |
447 err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_LEVEL_200 | 458 err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX; |
448 + NGX_HTTP_LEVEL_300 | |
449 + NGX_HTTP_LEVEL_400; | |
450 switch (error) { | 459 switch (error) { |
451 case NGX_HTTP_TO_HTTPS: | 460 case NGX_HTTP_TO_HTTPS: |
452 case NGX_HTTPS_CERT_ERROR: | 461 case NGX_HTTPS_CERT_ERROR: |
453 case NGX_HTTPS_NO_CERT: | 462 case NGX_HTTPS_NO_CERT: |
454 case NGX_HTTP_REQUEST_HEADER_TOO_LARGE: | 463 case NGX_HTTP_REQUEST_HEADER_TOO_LARGE: |
568 | 577 |
569 if (location == NULL) { | 578 if (location == NULL) { |
570 return NGX_ERROR; | 579 return NGX_ERROR; |
571 } | 580 } |
572 | 581 |
573 if (overwrite >= NGX_HTTP_MOVED_PERMANENTLY | 582 if (overwrite != NGX_HTTP_MOVED_PERMANENTLY |
574 && overwrite <= NGX_HTTP_SEE_OTHER) | 583 && overwrite != NGX_HTTP_MOVED_TEMPORARILY |
584 && overwrite != NGX_HTTP_SEE_OTHER | |
585 && overwrite != NGX_HTTP_TEMPORARY_REDIRECT) | |
575 { | 586 { |
576 r->err_status = overwrite; | |
577 | |
578 } else { | |
579 r->err_status = NGX_HTTP_MOVED_TEMPORARILY; | 587 r->err_status = NGX_HTTP_MOVED_TEMPORARILY; |
580 } | 588 } |
581 | 589 |
582 location->hash = 1; | 590 location->hash = 1; |
583 ngx_str_set(&location->key, "Location"); | 591 ngx_str_set(&location->key, "Location"); |
593 return ngx_http_send_refresh(r); | 601 return ngx_http_send_refresh(r); |
594 } | 602 } |
595 | 603 |
596 return ngx_http_send_special_response(r, clcf, r->err_status | 604 return ngx_http_send_special_response(r, clcf, r->err_status |
597 - NGX_HTTP_MOVED_PERMANENTLY | 605 - NGX_HTTP_MOVED_PERMANENTLY |
598 + NGX_HTTP_LEVEL_200); | 606 + NGX_HTTP_OFF_3XX); |
599 } | 607 } |
600 | 608 |
601 | 609 |
602 static ngx_int_t | 610 static ngx_int_t |
603 ngx_http_send_special_response(ngx_http_request_t *r, | 611 ngx_http_send_special_response(ngx_http_request_t *r, |
624 if (ngx_http_error_pages[err].len) { | 632 if (ngx_http_error_pages[err].len) { |
625 r->headers_out.content_length_n = ngx_http_error_pages[err].len + len; | 633 r->headers_out.content_length_n = ngx_http_error_pages[err].len + len; |
626 if (clcf->msie_padding | 634 if (clcf->msie_padding |
627 && (r->headers_in.msie || r->headers_in.chrome) | 635 && (r->headers_in.msie || r->headers_in.chrome) |
628 && r->http_version >= NGX_HTTP_VERSION_10 | 636 && r->http_version >= NGX_HTTP_VERSION_10 |
629 && err >= NGX_HTTP_LEVEL_300) | 637 && err >= NGX_HTTP_OFF_4XX) |
630 { | 638 { |
631 r->headers_out.content_length_n += | 639 r->headers_out.content_length_n += |
632 sizeof(ngx_http_msie_padding) - 1; | 640 sizeof(ngx_http_msie_padding) - 1; |
633 msie_padding = 1; | 641 msie_padding = 1; |
634 } | 642 } |