comparison src/http/ngx_http_request.c @ 214:0ad9eeb6ac7f NGINX_0_3_54

nginx 0.3.54 *) 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; bug appeared in 0.3.53.
author Igor Sysoev <http://sysoev.ru>
date Tue, 11 Jul 2006 00:00:00 +0400
parents 56688ed172c8
children fa32d59d9a15
comparison
equal deleted inserted replaced
213:405beeeadf7f 214:0ad9eeb6ac7f
41 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); 41 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
42 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error); 42 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error);
43 static void ngx_http_close_connection(ngx_connection_t *c); 43 static void ngx_http_close_connection(ngx_connection_t *c);
44 44
45 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); 45 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
46 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, 46 static u_char *ngx_http_log_error_handler(ngx_http_request_t *r,
47 size_t len); 47 ngx_http_request_t *sr, u_char *buf, size_t len);
48 48
49 #if (NGX_HTTP_SSL) 49 #if (NGX_HTTP_SSL)
50 static void ngx_http_ssl_handshake(ngx_event_t *rev); 50 static void ngx_http_ssl_handshake(ngx_event_t *rev);
51 static void ngx_http_ssl_handshake_handler(ngx_connection_t *c); 51 static void ngx_http_ssl_handshake_handler(ngx_connection_t *c);
52 #endif 52 #endif
160 return; 160 return;
161 } 161 }
162 162
163 ctx->client = &c->addr_text; 163 ctx->client = &c->addr_text;
164 ctx->request = NULL; 164 ctx->request = NULL;
165 ctx->current_request = NULL;
165 166
166 c->log->connection = c->number; 167 c->log->connection = c->number;
167 c->log->handler = ngx_http_log_error; 168 c->log->handler = ngx_http_log_error;
168 c->log->data = ctx; 169 c->log->data = ctx;
169 c->log->action = "reading client request line"; 170 c->log->action = "reading client request line";
425 426
426 r->http_state = NGX_HTTP_READING_REQUEST_STATE; 427 r->http_state = NGX_HTTP_READING_REQUEST_STATE;
427 428
428 ctx = c->log->data; 429 ctx = c->log->data;
429 ctx->request = r; 430 ctx->request = r;
431 ctx->current_request = r;
430 r->log_handler = ngx_http_log_error_handler; 432 r->log_handler = ngx_http_log_error_handler;
431 433
432 #if (NGX_STAT_STUB) 434 #if (NGX_STAT_STUB)
433 ngx_atomic_fetch_add(ngx_stat_reading, 1); 435 ngx_atomic_fetch_add(ngx_stat_reading, 1);
434 r->stat_reading = 1; 436 r->stat_reading = 1;
539 { 541 {
540 ssize_t n; 542 ssize_t n;
541 ngx_int_t rc, rv; 543 ngx_int_t rc, rv;
542 ngx_connection_t *c; 544 ngx_connection_t *c;
543 ngx_http_request_t *r; 545 ngx_http_request_t *r;
544 ngx_http_log_ctx_t *ctx;
545 546
546 c = rev->data; 547 c = rev->data;
547 r = c->data; 548 r = c->data;
548 549
549 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, 550 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
720 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 721 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
721 return; 722 return;
722 } 723 }
723 724
724 if (rv == NGX_DECLINED) { 725 if (rv == NGX_DECLINED) {
725 ctx = c->log->data;
726 ctx->request = r;
727
728 r->request_line.len = r->header_in->end - r->request_start; 726 r->request_line.len = r->header_in->end - r->request_start;
729 r->request_line.data = r->request_start; 727 r->request_line.data = r->request_start;
730 728
731 ngx_log_error(NGX_LOG_INFO, c->log, 0, 729 ngx_log_error(NGX_LOG_INFO, c->log, 0,
732 "client sent too long URI"); 730 "client sent too long URI");
1426 static void 1424 static void
1427 ngx_http_request_handler(ngx_event_t *ev) 1425 ngx_http_request_handler(ngx_event_t *ev)
1428 { 1426 {
1429 ngx_connection_t *c; 1427 ngx_connection_t *c;
1430 ngx_http_request_t *r; 1428 ngx_http_request_t *r;
1429 ngx_http_log_ctx_t *ctx;
1431 1430
1432 c = ev->data; 1431 c = ev->data;
1433 r = c->data; 1432 r = c->data;
1434 1433
1434 ctx = c->log->data;
1435 ctx->current_request = r;
1436
1435 if (ev->write) { 1437 if (ev->write) {
1436 r->write_event_handler(r); 1438 r->write_event_handler(r);
1437 1439
1438 } else { 1440 } else {
1439 r->read_event_handler(r); 1441 r->read_event_handler(r);
1443 1445
1444 void 1446 void
1445 ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) 1447 ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
1446 { 1448 {
1447 ngx_http_request_t *pr; 1449 ngx_http_request_t *pr;
1450 ngx_http_log_ctx_t *ctx;
1448 ngx_http_core_loc_conf_t *clcf; 1451 ngx_http_core_loc_conf_t *clcf;
1449 1452
1450 if (rc == NGX_DONE) { 1453 if (rc == NGX_DONE) {
1451 /* the request pool may be already destroyed */ 1454 /* the request pool may be already destroyed */
1452 return; 1455 return;
1520 "http parent request: \"%V?%V\"", &pr->uri, &pr->args); 1523 "http parent request: \"%V?%V\"", &pr->uri, &pr->args);
1521 1524
1522 if (rc != NGX_AGAIN) { 1525 if (rc != NGX_AGAIN) {
1523 r->connection->data = pr; 1526 r->connection->data = pr;
1524 } 1527 }
1528
1529 ctx = r->connection->log->data;
1530 ctx->current_request = pr;
1525 1531
1526 if (pr->postponed) { 1532 if (pr->postponed) {
1527 1533
1528 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1534 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1529 "http request: \"%V?%V\" has postponed", 1535 "http request: \"%V?%V\" has postponed",
2362 len -= p - buf; 2368 len -= p - buf;
2363 2369
2364 r = ctx->request; 2370 r = ctx->request;
2365 2371
2366 if (r) { 2372 if (r) {
2367 return r->log_handler(r, p, len); 2373 return r->log_handler(r, ctx->current_request, p, len);
2368 } 2374 }
2369 2375
2370 return p; 2376 return p;
2371 } 2377 }
2372 2378
2373 2379
2374 static u_char * 2380 static u_char *
2375 ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, size_t len) 2381 ngx_http_log_error_handler(ngx_http_request_t *r, ngx_http_request_t *sr,
2376 { 2382 u_char *buf, size_t len)
2377 u_char *p; 2383 {
2384 u_char *p;
2385 ngx_http_upstream_t *u;
2386 ngx_peer_connection_t *peer;
2378 2387
2379 if (r->server_name.data) { 2388 if (r->server_name.data) {
2380 p = ngx_snprintf(buf, len, ", server: %V", &r->server_name); 2389 p = ngx_snprintf(buf, len, ", server: %V", &r->server_name);
2381 len -= p - buf; 2390 len -= p - buf;
2382 buf = p; 2391 buf = p;
2404 len -= p - buf; 2413 len -= p - buf;
2405 buf = p; 2414 buf = p;
2406 } 2415 }
2407 } 2416 }
2408 2417
2418 if (r != sr) {
2419 p = ngx_snprintf(buf, len, ", subrequest: \"%V\"", &sr->uri);
2420 len -= p - buf;
2421 buf = p;
2422 }
2423
2424 u = sr->upstream;
2425
2426 if (u) {
2427 peer = &u->peer;
2428
2429 p = ngx_snprintf(buf, len, ", upstream: \"%V%V%s%V\"",
2430 &u->conf->schema,
2431 &peer->peers->peer[peer->cur_peer].name,
2432 peer->peers->peer[peer->cur_peer].uri_separator,
2433 &u->uri);
2434 len -= p - buf;
2435 buf = p;
2436 }
2437
2409 return ngx_http_log_error_info(r, buf, len); 2438 return ngx_http_log_error_info(r, buf, len);
2410 } 2439 }
2411 2440
2412 2441
2413 u_char * 2442 u_char *