Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 2267:920be89a3d2d
ngx_http_upstream_intercept_errors()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 30 Sep 2008 14:57:09 +0000 |
parents | f5a9f35e8344 |
children | 33556140681a |
comparison
equal
deleted
inserted
replaced
2266:6223d5a9e87f | 2267:920be89a3d2d |
---|---|
20 ngx_http_upstream_t *u); | 20 ngx_http_upstream_t *u); |
21 static void ngx_http_upstream_send_request(ngx_http_request_t *r, | 21 static void ngx_http_upstream_send_request(ngx_http_request_t *r, |
22 ngx_http_upstream_t *u); | 22 ngx_http_upstream_t *u); |
23 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); | 23 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); |
24 static void ngx_http_upstream_process_header(ngx_event_t *rev); | 24 static void ngx_http_upstream_process_header(ngx_event_t *rev); |
25 static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r, | |
26 ngx_http_upstream_t *u); | |
25 static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c); | 27 static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c); |
26 static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev); | 28 static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev); |
27 static void ngx_http_upstream_send_response(ngx_http_request_t *r, | 29 static void ngx_http_upstream_send_response(ngx_http_request_t *r, |
28 ngx_http_upstream_t *u); | 30 ngx_http_upstream_t *u); |
29 static void | 31 static void |
1045 ngx_list_part_t *part; | 1047 ngx_list_part_t *part; |
1046 ngx_table_elt_t *h; | 1048 ngx_table_elt_t *h; |
1047 ngx_connection_t *c; | 1049 ngx_connection_t *c; |
1048 ngx_http_request_t *r; | 1050 ngx_http_request_t *r; |
1049 ngx_http_upstream_t *u; | 1051 ngx_http_upstream_t *u; |
1050 ngx_http_err_page_t *err_page; | |
1051 ngx_http_core_loc_conf_t *clcf; | |
1052 ngx_http_upstream_header_t *hh; | 1052 ngx_http_upstream_header_t *hh; |
1053 ngx_http_upstream_main_conf_t *umcf; | 1053 ngx_http_upstream_main_conf_t *umcf; |
1054 | 1054 |
1055 c = rev->data; | 1055 c = rev->data; |
1056 r = c->data; | 1056 r = c->data; |
1217 return; | 1217 return; |
1218 } | 1218 } |
1219 } | 1219 } |
1220 | 1220 |
1221 | 1221 |
1222 if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST | 1222 if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST) { |
1223 && u->conf->intercept_errors) | 1223 |
1224 { | 1224 if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) { |
1225 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1225 return; |
1226 | |
1227 if (clcf->error_pages) { | |
1228 | |
1229 err_page = clcf->error_pages->elts; | |
1230 for (i = 0; i < clcf->error_pages->nelts; i++) { | |
1231 if (err_page[i].status == (ngx_int_t) u->headers_in.status_n) { | |
1232 | |
1233 if (u->headers_in.status_n == NGX_HTTP_UNAUTHORIZED) { | |
1234 | |
1235 r->headers_out.www_authenticate = | |
1236 ngx_list_push(&r->headers_out.headers); | |
1237 | |
1238 if (r->headers_out.www_authenticate == NULL) { | |
1239 ngx_http_upstream_finalize_request(r, u, | |
1240 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1241 return; | |
1242 } | |
1243 | |
1244 *r->headers_out.www_authenticate = | |
1245 *u->headers_in.www_authenticate; | |
1246 } | |
1247 | |
1248 ngx_http_upstream_finalize_request(r, u, | |
1249 u->headers_in.status_n); | |
1250 return; | |
1251 } | |
1252 } | |
1253 } | 1226 } |
1254 } | 1227 } |
1255 | 1228 |
1256 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | 1229 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); |
1257 | 1230 |
1401 } | 1374 } |
1402 | 1375 |
1403 rev->handler = ngx_http_upstream_process_body_in_memory; | 1376 rev->handler = ngx_http_upstream_process_body_in_memory; |
1404 | 1377 |
1405 ngx_http_upstream_process_body_in_memory(rev); | 1378 ngx_http_upstream_process_body_in_memory(rev); |
1379 } | |
1380 | |
1381 | |
1382 static ngx_int_t | |
1383 ngx_http_upstream_intercept_errors(ngx_http_request_t *r, | |
1384 ngx_http_upstream_t *u) | |
1385 { | |
1386 ngx_int_t status; | |
1387 ngx_uint_t i; | |
1388 ngx_table_elt_t *h; | |
1389 ngx_http_err_page_t *err_page; | |
1390 ngx_http_core_loc_conf_t *clcf; | |
1391 | |
1392 if (!u->conf->intercept_errors) { | |
1393 return NGX_DECLINED; | |
1394 } | |
1395 | |
1396 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1397 | |
1398 if (clcf->error_pages == NULL) { | |
1399 return NGX_DECLINED; | |
1400 } | |
1401 | |
1402 status = u->headers_in.status_n; | |
1403 | |
1404 err_page = clcf->error_pages->elts; | |
1405 for (i = 0; i < clcf->error_pages->nelts; i++) { | |
1406 | |
1407 if (err_page[i].status == status) { | |
1408 | |
1409 if (status == NGX_HTTP_UNAUTHORIZED) { | |
1410 | |
1411 h = ngx_list_push(&r->headers_out.headers); | |
1412 | |
1413 if (h == NULL) { | |
1414 ngx_http_upstream_finalize_request(r, u, | |
1415 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1416 return NGX_OK; | |
1417 } | |
1418 | |
1419 *h = *u->headers_in.www_authenticate; | |
1420 | |
1421 r->headers_out.www_authenticate = h; | |
1422 } | |
1423 | |
1424 ngx_http_upstream_finalize_request(r, u, status); | |
1425 | |
1426 return NGX_OK; | |
1427 } | |
1428 } | |
1429 | |
1430 return NGX_DECLINED; | |
1406 } | 1431 } |
1407 | 1432 |
1408 | 1433 |
1409 static ngx_int_t | 1434 static ngx_int_t |
1410 ngx_http_upstream_test_connect(ngx_connection_t *c) | 1435 ngx_http_upstream_test_connect(ngx_connection_t *c) |