Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 665:5fd7a5e99047 release-0.3.54
nginx-0.3.54-RELEASE import
*) Feature: nginx now logs the subrequest information to the error log.
*) Feature: the "proxy_next_upstream", "fastcgi_next_upstream", and
"memcached_next_upstream" directives support the "off" parameter.
*) Feature: the "debug_connection" directive supports the CIDR address
form.
*) Bugfix: if a response of proxied server or FastCGI server was
converted from UTF-8 or back, then it may be transferred incomplete.
*) Bugfix: the $upstream_response_time variable had the time of the
first request to a backend only.
*) Bugfix: nginx could not be built on amd64 platform; the bug had
appeared in 0.3.53.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 11 Jul 2006 13:20:19 +0000 |
parents | 6d5c1535bb9d |
children | 63a820b0bc6c |
comparison
equal
deleted
inserted
replaced
664:db08f60f873f | 665:5fd7a5e99047 |
---|---|
76 static size_t ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r, | 76 static size_t ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r, |
77 uintptr_t data); | 77 uintptr_t data); |
78 static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r, | 78 static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r, |
79 u_char *buf, ngx_http_log_op_t *op); | 79 u_char *buf, ngx_http_log_op_t *op); |
80 | 80 |
81 static u_char *ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, | |
82 size_t len); | |
83 | |
84 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); | 81 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
85 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, | 82 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
86 ngx_http_variable_value_t *v, uintptr_t data); | 83 ngx_http_variable_value_t *v, uintptr_t data); |
87 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | 84 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, |
88 ngx_http_variable_value_t *v, uintptr_t data); | 85 ngx_http_variable_value_t *v, uintptr_t data); |
291 | 288 |
292 | 289 |
293 void | 290 void |
294 ngx_http_upstream_init(ngx_http_request_t *r) | 291 ngx_http_upstream_init(ngx_http_request_t *r) |
295 { | 292 { |
296 ngx_time_t *tp; | |
297 ngx_connection_t *c; | 293 ngx_connection_t *c; |
298 ngx_http_cleanup_t *cln; | 294 ngx_http_cleanup_t *cln; |
299 ngx_http_upstream_t *u; | 295 ngx_http_upstream_t *u; |
300 ngx_http_core_loc_conf_t *clcf; | 296 ngx_http_core_loc_conf_t *clcf; |
301 | 297 |
335 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 331 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
336 return; | 332 return; |
337 } | 333 } |
338 | 334 |
339 u->peer.log = r->connection->log; | 335 u->peer.log = r->connection->log; |
340 u->saved_log_handler = r->log_handler; | |
341 r->log_handler = ngx_http_upstream_log_error; | |
342 | 336 |
343 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 337 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
344 | 338 |
345 u->output.sendfile = r->connection->sendfile; | 339 u->output.sendfile = r->connection->sendfile; |
346 u->output.pool = r->pool; | 340 u->output.pool = r->pool; |
356 != NGX_OK) | 350 != NGX_OK) |
357 { | 351 { |
358 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 352 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
359 return; | 353 return; |
360 } | 354 } |
361 | |
362 u->state = ngx_array_push(&u->states); | |
363 if (u->state == NULL) { | |
364 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
365 return; | |
366 } | |
367 | |
368 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
369 | |
370 tp = ngx_timeofday(); | |
371 | |
372 u->state->response_time = tp->sec * 1000 + tp->msec; | |
373 | 355 |
374 cln = ngx_http_cleanup_add(r, 0); | 356 cln = ngx_http_cleanup_add(r, 0); |
375 if (cln == NULL) { | 357 if (cln == NULL) { |
376 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 358 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
377 return; | 359 return; |
526 | 508 |
527 static void | 509 static void |
528 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | 510 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) |
529 { | 511 { |
530 ngx_int_t rc; | 512 ngx_int_t rc; |
513 ngx_time_t *tp; | |
531 ngx_connection_t *c; | 514 ngx_connection_t *c; |
532 | 515 |
533 r->connection->log->action = "connecting to upstream"; | 516 r->connection->log->action = "connecting to upstream"; |
534 | 517 |
535 r->connection->single_connection = 0; | 518 r->connection->single_connection = 0; |
519 | |
520 if (u->state && u->state->response_time) { | |
521 tp = ngx_timeofday(); | |
522 u->state->response_time = tp->sec * 1000 + tp->msec | |
523 - u->state->response_time; | |
524 } | |
525 | |
526 u->state = ngx_array_push(&u->states); | |
527 if (u->state == NULL) { | |
528 ngx_http_upstream_finalize_request(r, u, | |
529 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
530 return; | |
531 } | |
532 | |
533 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
534 | |
535 tp = ngx_timeofday(); | |
536 u->state->response_time = tp->sec * 1000 + tp->msec; | |
536 | 537 |
537 rc = ngx_event_connect_peer(&u->peer); | 538 rc = ngx_event_connect_peer(&u->peer); |
538 | 539 |
539 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 540 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
540 "http upstream connect: %i", rc); | 541 "http upstream connect: %i", rc); |
758 | 759 |
759 u->buffer.pos = u->buffer.start; | 760 u->buffer.pos = u->buffer.start; |
760 u->buffer.last = u->buffer.start; | 761 u->buffer.last = u->buffer.start; |
761 | 762 |
762 #endif | 763 #endif |
763 | |
764 /* add one more state */ | |
765 | |
766 u->state = ngx_array_push(&u->states); | |
767 if (u->state == NULL) { | |
768 return NGX_ERROR; | |
769 } | |
770 | |
771 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
772 | 764 |
773 return NGX_OK; | 765 return NGX_OK; |
774 } | 766 } |
775 | 767 |
776 | 768 |
1986 "http upstream cache fd: %d", | 1978 "http upstream cache fd: %d", |
1987 u->cache->ctx.file.fd); | 1979 u->cache->ctx.file.fd); |
1988 } | 1980 } |
1989 #endif | 1981 #endif |
1990 | 1982 |
1991 r->log_handler = u->saved_log_handler; | |
1992 | |
1993 if (rc == NGX_DECLINED) { | 1983 if (rc == NGX_DECLINED) { |
1994 return; | 1984 return; |
1995 } | 1985 } |
1996 | 1986 |
1997 r->connection->log->action = "sending to client"; | 1987 r->connection->log->action = "sending to client"; |
2452 } | 2442 } |
2453 | 2443 |
2454 *buf++ = ','; | 2444 *buf++ = ','; |
2455 *buf++ = ' '; | 2445 *buf++ = ' '; |
2456 } | 2446 } |
2457 } | |
2458 | |
2459 | |
2460 static u_char * | |
2461 ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, size_t len) | |
2462 { | |
2463 u_char *p; | |
2464 ngx_http_upstream_t *u; | |
2465 ngx_peer_connection_t *peer; | |
2466 | |
2467 u = r->upstream; | |
2468 peer = &u->peer; | |
2469 | |
2470 p = ngx_snprintf(buf, len, | |
2471 ", server: %V, URL: \"%V\"," | |
2472 " upstream: \"%V%V%s%V\"", | |
2473 &r->server_name, | |
2474 &r->unparsed_uri, | |
2475 &u->conf->schema, | |
2476 &peer->peers->peer[peer->cur_peer].name, | |
2477 peer->peers->peer[peer->cur_peer].uri_separator, | |
2478 &u->uri); | |
2479 len -= p - buf; | |
2480 buf = p; | |
2481 | |
2482 return ngx_http_log_error_info(r, buf, len); | |
2483 } | 2447 } |
2484 | 2448 |
2485 | 2449 |
2486 static ngx_int_t | 2450 static ngx_int_t |
2487 ngx_http_upstream_add_variables(ngx_conf_t *cf) | 2451 ngx_http_upstream_add_variables(ngx_conf_t *cf) |