Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_request.c @ 10:46833bd150cb NGINX_0_1_5
nginx 0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 00:00:00 +0300 |
parents | 80ba094c6b3e |
children | 6f8b0dc0f8dd |
comparison
equal
deleted
inserted
replaced
9:77eee314ddbd | 10:46833bd150cb |
---|---|
32 static void ngx_http_set_lingering_close(ngx_http_request_t *r); | 32 static void ngx_http_set_lingering_close(ngx_http_request_t *r); |
33 static void ngx_http_lingering_close_handler(ngx_event_t *ev); | 33 static void ngx_http_lingering_close_handler(ngx_event_t *ev); |
34 | 34 |
35 static void ngx_http_client_error(ngx_http_request_t *r, | 35 static void ngx_http_client_error(ngx_http_request_t *r, |
36 int client_error, int error); | 36 int client_error, int error); |
37 static size_t ngx_http_log_error(void *data, char *buf, size_t len); | 37 static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len); |
38 | 38 |
39 | 39 |
40 /* NGX_HTTP_PARSE_... errors */ | 40 /* NGX_HTTP_PARSE_... errors */ |
41 | 41 |
42 static char *client_header_errors[] = { | 42 static char *client_header_errors[] = { |
43 "client %s sent invalid method", | 43 "client %V sent invalid method \"%V\"", |
44 "client %s sent invalid request", | 44 "client %V sent invalid request \"%V\"", |
45 "client %s sent too long URI", | 45 "client %V sent too long URI in request \"%V\"", |
46 "client %s sent invalid method in HTTP/0.9 request", | 46 "client %V sent invalid method in HTTP/0.9 request \"%V\"", |
47 | 47 |
48 "client %s sent invalid header, URL: %s", | 48 "client %V sent invalid header, URL: \"%V\"", |
49 "client %s sent too long header line, URL: %s", | 49 "client %V sent too long header line, URL: \"%V\"", |
50 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", | 50 "client %V sent HTTP/1.1 request without \"Host\" header, URL: \"%V\"", |
51 "client %s sent invalid \"Content-Length\" header, URL: %s", | 51 "client %V sent invalid \"Content-Length\" header, URL: \"%V\"", |
52 "client %s sent POST method without \"Content-Length\" header, URL: %s", | 52 "client %V sent POST method without \"Content-Length\" header, URL: \"%V\"", |
53 "client %s sent plain HTTP request to HTTPS port, URL: %s", | |
54 "client %s sent invalid \"Host\" header \"%s\", URL: %s" | |
55 }; | 53 }; |
56 | 54 |
57 | 55 |
58 ngx_http_header_t ngx_http_headers_in[] = { | 56 ngx_http_header_t ngx_http_headers_in[] = { |
59 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) }, | 57 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) }, |
103 void ngx_http_init_connection(ngx_connection_t *c) | 101 void ngx_http_init_connection(ngx_connection_t *c) |
104 { | 102 { |
105 ngx_event_t *rev; | 103 ngx_event_t *rev; |
106 ngx_http_log_ctx_t *ctx; | 104 ngx_http_log_ctx_t *ctx; |
107 | 105 |
108 if (!(ctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { | 106 if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { |
109 ngx_http_close_connection(c); | 107 ngx_http_close_connection(c); |
110 return; | 108 return; |
111 } | 109 } |
112 | 110 |
113 ctx->connection = c->number; | 111 ctx->connection = c->number; |
114 ctx->client = c->addr_text.data; | 112 ctx->client = &c->addr_text; |
115 ctx->action = "reading client request line"; | 113 ctx->action = "reading client request line"; |
114 ctx->request = NULL; | |
116 c->log->data = ctx; | 115 c->log->data = ctx; |
117 c->log->handler = ngx_http_log_error; | 116 c->log->handler = ngx_http_log_error; |
118 c->log_error = NGX_ERROR_INFO; | 117 c->log_error = NGX_ERROR_INFO; |
119 | 118 |
120 rev = c->read; | 119 rev = c->read; |
276 * the server address. | 275 * the server address. |
277 * | 276 * |
278 * AcceptEx() already gave this address. | 277 * AcceptEx() already gave this address. |
279 */ | 278 */ |
280 | 279 |
281 #if (WIN32) | 280 #if (NGX_WIN32) |
282 if (c->local_sockaddr) { | 281 if (c->local_sockaddr) { |
283 r->in_addr = | 282 r->in_addr = |
284 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | 283 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; |
285 | 284 |
286 } else { | 285 } else { |
293 return; | 292 return; |
294 } | 293 } |
295 | 294 |
296 r->in_addr = addr_in.sin_addr.s_addr; | 295 r->in_addr = addr_in.sin_addr.s_addr; |
297 | 296 |
298 #if (WIN32) | 297 #if (NGX_WIN32) |
299 } | 298 } |
300 #endif | 299 #endif |
301 | 300 |
302 /* the last in_port->addrs address is "*" */ | 301 /* the last in_port->addrs address is "*" */ |
303 | 302 |
426 | 425 |
427 #if (NGX_HTTP_SSL) | 426 #if (NGX_HTTP_SSL) |
428 | 427 |
429 static void ngx_http_ssl_handshake(ngx_event_t *rev) | 428 static void ngx_http_ssl_handshake(ngx_event_t *rev) |
430 { | 429 { |
431 int n; | 430 u_char buf[1]; |
431 ssize_t n; | |
432 ngx_int_t rc; | 432 ngx_int_t rc; |
433 u_char buf[1]; | |
434 ngx_connection_t *c; | 433 ngx_connection_t *c; |
435 ngx_http_request_t *r; | 434 ngx_http_request_t *r; |
436 | 435 |
437 c = rev->data; | 436 c = rev->data; |
438 r = c->data; | 437 r = c->data; |
452 } | 451 } |
453 | 452 |
454 if (n == 1) { | 453 if (n == 1) { |
455 if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { | 454 if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { |
456 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, | 455 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, |
457 "https ssl handshake: 0x%X", buf[0]); | 456 "https ssl handshake: 0x%02Xd", buf[0]); |
458 | 457 |
459 c->recv = ngx_ssl_recv; | 458 c->recv = ngx_ssl_recv; |
460 c->send_chain = ngx_ssl_send_chain; | 459 c->send_chain = ngx_ssl_send_chain; |
461 | 460 |
462 rc = ngx_ssl_handshake(c); | 461 rc = ngx_ssl_handshake(c); |
486 #endif | 485 #endif |
487 | 486 |
488 | 487 |
489 static void ngx_http_process_request_line(ngx_event_t *rev) | 488 static void ngx_http_process_request_line(ngx_event_t *rev) |
490 { | 489 { |
491 u_char *p; | |
492 ssize_t n; | 490 ssize_t n; |
493 ngx_int_t rc, rv; | 491 ngx_int_t rc, rv; |
494 ngx_connection_t *c; | 492 ngx_connection_t *c; |
495 ngx_http_request_t *r; | 493 ngx_http_request_t *r; |
496 ngx_http_log_ctx_t *ctx; | 494 ngx_http_log_ctx_t *ctx; |
522 | 520 |
523 if (rc == NGX_OK) { | 521 if (rc == NGX_OK) { |
524 | 522 |
525 /* the request line has been parsed successfully */ | 523 /* the request line has been parsed successfully */ |
526 | 524 |
527 /* copy unparsed URI */ | 525 r->request_line.len = r->request_end - r->request_start; |
528 | 526 r->request_line.data = r->request_start; |
529 r->unparsed_uri.len = r->uri_end - r->uri_start; | 527 |
530 r->unparsed_uri.data = ngx_palloc(r->pool, r->unparsed_uri.len + 1); | |
531 if (r->unparsed_uri.data == NULL) { | |
532 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
533 ngx_http_close_connection(c); | |
534 return; | |
535 } | |
536 | |
537 ngx_cpystrn(r->unparsed_uri.data, r->uri_start, | |
538 r->unparsed_uri.len + 1); | |
539 | |
540 | |
541 /* copy URI */ | |
542 | 528 |
543 if (r->args_start) { | 529 if (r->args_start) { |
544 r->uri.len = r->args_start - 1 - r->uri_start; | 530 r->uri.len = r->args_start - 1 - r->uri_start; |
545 } else { | 531 } else { |
546 r->uri.len = r->uri_end - r->uri_start; | 532 r->uri.len = r->uri_end - r->uri_start; |
547 } | 533 } |
548 | 534 |
549 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { | |
550 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
551 ngx_http_close_connection(c); | |
552 return; | |
553 } | |
554 | |
555 if (r->complex_uri || r->quoted_uri) { | 535 if (r->complex_uri || r->quoted_uri) { |
536 | |
537 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { | |
538 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
539 ngx_http_close_connection(c); | |
540 return; | |
541 } | |
542 | |
556 rc = ngx_http_parse_complex_uri(r); | 543 rc = ngx_http_parse_complex_uri(r); |
557 | 544 |
558 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | 545 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { |
559 ngx_http_close_request(r, rc); | 546 ngx_http_close_request(r, rc); |
560 ngx_http_close_connection(c); | 547 ngx_http_close_connection(c); |
561 return; | 548 return; |
562 } | 549 } |
563 | 550 |
564 if (rc != NGX_OK) { | 551 if (rc != NGX_OK) { |
565 r->request_line.len = r->request_end - r->request_start; | |
566 r->request_line.data = r->request_start; | |
567 | |
568 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); | 552 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); |
569 return; | 553 return; |
570 } | 554 } |
571 | 555 |
572 } else { | 556 } else { |
573 ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); | 557 r->uri.data = r->uri_start; |
574 } | 558 } |
575 | 559 |
576 | 560 r->unparsed_uri.len = r->uri_end - r->uri_start; |
577 r->request_line.len = r->request_end - r->request_start; | 561 r->unparsed_uri.data = r->uri_start; |
578 r->request_line.data = r->request_start; | 562 |
579 r->request_line.data[r->request_line.len] = '\0'; | |
580 | 563 |
581 if (r->method == 0) { | 564 if (r->method == 0) { |
582 r->method_name.len = r->method_end - r->request_start + 1; | 565 r->method_name.len = r->method_end - r->request_start + 1; |
583 r->method_name.data = r->request_line.data; | 566 r->method_name.data = r->request_line.data; |
584 } | 567 } |
585 | 568 |
569 | |
586 if (r->uri_ext) { | 570 if (r->uri_ext) { |
587 | |
588 /* copy URI extention */ | |
589 | |
590 if (r->args_start) { | 571 if (r->args_start) { |
591 r->exten.len = r->args_start - 1 - r->uri_ext; | 572 r->exten.len = r->args_start - 1 - r->uri_ext; |
592 } else { | 573 } else { |
593 r->exten.len = r->uri_end - r->uri_ext; | 574 r->exten.len = r->uri_end - r->uri_ext; |
594 } | 575 } |
595 | 576 |
596 if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { | 577 r->exten.data = r->uri_ext; |
597 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 578 } |
598 ngx_http_close_connection(c); | 579 |
599 return; | |
600 } | |
601 | |
602 ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1); | |
603 } | |
604 | 580 |
605 if (r->args_start && r->uri_end > r->args_start) { | 581 if (r->args_start && r->uri_end > r->args_start) { |
606 | |
607 /* copy URI arguments */ | |
608 | |
609 r->args.len = r->uri_end - r->args_start; | 582 r->args.len = r->uri_end - r->args_start; |
610 | 583 r->args.data = r->args_start; |
611 if (!(r->args.data = ngx_palloc(r->pool, r->args.len + 1))) { | 584 } |
612 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 585 |
613 ngx_http_close_connection(c); | |
614 return; | |
615 } | |
616 | |
617 ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); | |
618 } | |
619 | 586 |
620 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 587 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
621 "http request line: \"%s\"", r->request_line.data); | 588 "http request line: \"%V\"", &r->request_line); |
622 | 589 |
623 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 590 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
624 "http uri: \"%s\"", r->uri.data); | 591 "http uri: \"%V\"", &r->uri); |
625 | 592 |
626 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 593 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
627 "http args: \"%s\"", | 594 "http args: \"%V\"", &r->args); |
628 r->args.data ? r->args.data : (u_char *) ""); | |
629 | 595 |
630 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 596 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
631 "http exten: \"%s\"", | 597 "http exten: \"%V\"", &r->exten); |
632 r->exten.data ? r->exten.data : (u_char *) ""); | 598 |
599 ctx = c->log->data; | |
600 ctx->request = r; | |
633 | 601 |
634 if (r->http_version < NGX_HTTP_VERSION_10) { | 602 if (r->http_version < NGX_HTTP_VERSION_10) { |
635 rev->event_handler = ngx_http_block_read; | 603 rev->event_handler = ngx_http_block_read; |
636 ngx_http_handler(r); | 604 ngx_http_handler(r); |
637 return; | 605 return; |
653 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 621 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
654 ngx_http_close_connection(c); | 622 ngx_http_close_connection(c); |
655 return; | 623 return; |
656 } | 624 } |
657 | 625 |
658 | |
659 ctx = c->log->data; | |
660 ctx->action = "reading client request headers"; | 626 ctx->action = "reading client request headers"; |
661 ctx->url = r->unparsed_uri.data; | |
662 | 627 |
663 rev->event_handler = ngx_http_process_request_headers; | 628 rev->event_handler = ngx_http_process_request_headers; |
664 ngx_http_process_request_headers(rev); | 629 ngx_http_process_request_headers(rev); |
665 | 630 |
666 return; | 631 return; |
667 | 632 |
668 } else if (rc != NGX_AGAIN) { | 633 } else if (rc != NGX_AGAIN) { |
669 | 634 |
670 /* there was error while a request line parsing */ | 635 /* there was error while a request line parsing */ |
671 | 636 |
637 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); | |
638 | |
639 #if 0 | |
672 for (p = r->request_start; p < r->header_in->last; p++) { | 640 for (p = r->request_start; p < r->header_in->last; p++) { |
673 if (*p == CR || *p == LF) { | 641 if (*p == CR || *p == LF) { |
674 break; | 642 break; |
675 } | 643 } |
676 } | 644 } |
684 | 652 |
685 ngx_http_client_error(r, rc, | 653 ngx_http_client_error(r, rc, |
686 (rc == NGX_HTTP_PARSE_INVALID_METHOD) ? | 654 (rc == NGX_HTTP_PARSE_INVALID_METHOD) ? |
687 NGX_HTTP_NOT_IMPLEMENTED: | 655 NGX_HTTP_NOT_IMPLEMENTED: |
688 NGX_HTTP_BAD_REQUEST); | 656 NGX_HTTP_BAD_REQUEST); |
657 #endif | |
658 | |
689 return; | 659 return; |
690 } | 660 } |
691 | 661 |
692 /* NGX_AGAIN: a request line parsing is still incomplete */ | 662 /* NGX_AGAIN: a request line parsing is still incomplete */ |
693 | 663 |
809 } | 779 } |
810 } | 780 } |
811 } | 781 } |
812 | 782 |
813 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 783 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
814 "http header: \"%s: %s\"", | 784 "http header: \"%V: %V\"", |
815 h->key.data, h->value.data); | 785 &h->key, &h->value); |
816 | 786 |
817 continue; | 787 continue; |
818 | 788 |
819 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | 789 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { |
820 | 790 |
971 | 941 |
972 if (hc->nfree) { | 942 if (hc->nfree) { |
973 b = hc->free[--hc->nfree]; | 943 b = hc->free[--hc->nfree]; |
974 | 944 |
975 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 945 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
976 "http large header free: " PTR_FMT " " SIZE_T_FMT, | 946 "http large header free: %p %uz", |
977 b->pos, b->end - b->last); | 947 b->pos, b->end - b->last); |
978 | 948 |
979 } else if (hc->nbusy < cscf->large_client_header_buffers.num) { | 949 } else if (hc->nbusy < cscf->large_client_header_buffers.num) { |
980 | 950 |
981 if (hc->busy == NULL) { | 951 if (hc->busy == NULL) { |
991 if (b == NULL) { | 961 if (b == NULL) { |
992 return NGX_ERROR; | 962 return NGX_ERROR; |
993 } | 963 } |
994 | 964 |
995 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 965 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
996 "http large header alloc: " PTR_FMT " " SIZE_T_FMT, | 966 "http large header alloc: %p %uz", |
997 b->pos, b->end - b->last); | 967 b->pos, b->end - b->last); |
998 | 968 |
999 } else { | 969 } else { |
1000 return NGX_DECLINED; | 970 return NGX_DECLINED; |
1001 } | 971 } |
1093 | 1063 |
1094 name = r->virtual_names->elts; | 1064 name = r->virtual_names->elts; |
1095 for (i = 0; i < r->virtual_names->nelts; i++) { | 1065 for (i = 0; i < r->virtual_names->nelts; i++) { |
1096 | 1066 |
1097 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1067 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1098 "server name: %s", name[i].name.data); | 1068 "server name: %V", &name[i].name); |
1099 | 1069 |
1100 if (name[i].wildcard) { | 1070 if (name[i].wildcard) { |
1101 if (r->headers_in.host_name_len <= name[i].name.len) { | 1071 if (r->headers_in.host_name_len <= name[i].name.len) { |
1102 continue; | 1072 continue; |
1103 } | 1073 } |
1577 c = r->connection; | 1547 c = r->connection; |
1578 rev = c->read; | 1548 rev = c->read; |
1579 | 1549 |
1580 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); | 1550 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); |
1581 | 1551 |
1582 ctx = (ngx_http_log_ctx_t *) c->log->data; | 1552 ctx = c->log->data; |
1583 ctx->action = "closing request"; | 1553 ctx->action = "closing request"; |
1584 | 1554 |
1585 hc = r->http_connection; | 1555 hc = r->http_connection; |
1586 b = r->header_in; | 1556 b = r->header_in; |
1587 | 1557 |
1675 } else { | 1645 } else { |
1676 b->pos = b->start; | 1646 b->pos = b->start; |
1677 b->last = b->start; | 1647 b->last = b->start; |
1678 } | 1648 } |
1679 | 1649 |
1680 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d", | 1650 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d", |
1681 hc->free, hc->nfree); | 1651 hc->free, hc->nfree); |
1682 | 1652 |
1683 if (hc->free) { | 1653 if (hc->free) { |
1684 for (i = 0; i < hc->nfree; i++) { | 1654 for (i = 0; i < hc->nfree; i++) { |
1685 ngx_pfree(c->pool, hc->free[i]); | 1655 ngx_pfree(c->pool, hc->free[i]); |
1687 } | 1657 } |
1688 | 1658 |
1689 hc->nfree = 0; | 1659 hc->nfree = 0; |
1690 } | 1660 } |
1691 | 1661 |
1692 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d", | 1662 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d", |
1693 hc->busy, hc->nbusy); | 1663 hc->busy, hc->nbusy); |
1694 | 1664 |
1695 if (hc->busy) { | 1665 if (hc->busy) { |
1696 for (i = 0; i < hc->nbusy; i++) { | 1666 for (i = 0; i < hc->nbusy; i++) { |
1697 ngx_pfree(c->pool, hc->busy[i]); | 1667 ngx_pfree(c->pool, hc->busy[i]); |
1783 | 1753 |
1784 #if (HAVE_KQUEUE) | 1754 #if (HAVE_KQUEUE) |
1785 | 1755 |
1786 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 1756 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
1787 if (rev->pending_eof) { | 1757 if (rev->pending_eof) { |
1758 rev->log->handler = NULL; | |
1788 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, | 1759 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, |
1789 "kevent() reported that client %s closed " | 1760 "kevent() reported that client %V closed " |
1790 "keepalive connection", ctx->client); | 1761 "keepalive connection", ctx->client); |
1791 ngx_http_close_connection(c); | 1762 ngx_http_close_connection(c); |
1792 return; | 1763 return; |
1793 } | 1764 } |
1794 } | 1765 } |
1839 | 1810 |
1840 rev->log->handler = NULL; | 1811 rev->log->handler = NULL; |
1841 | 1812 |
1842 if (n == 0) { | 1813 if (n == 0) { |
1843 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, | 1814 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, |
1844 "client %s closed keepalive connection", ctx->client); | 1815 "client %V closed keepalive connection", ctx->client); |
1845 ngx_http_close_connection(c); | 1816 ngx_http_close_connection(c); |
1846 return; | 1817 return; |
1847 } | 1818 } |
1848 | 1819 |
1849 b->last += n; | 1820 b->last += n; |
2053 | 2024 |
2054 /* STUB */ | 2025 /* STUB */ |
2055 if (r->file.fd != NGX_INVALID_FILE) { | 2026 if (r->file.fd != NGX_INVALID_FILE) { |
2056 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | 2027 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
2057 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 2028 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
2058 ngx_close_file_n " \"%s\" failed", r->file.name.data); | 2029 ngx_close_file_n " \"%V\" failed", &r->file.name); |
2059 } | 2030 } |
2060 } | 2031 } |
2061 | 2032 |
2062 if (r->request_body | 2033 if (r->request_body |
2063 && r->request_body->temp_file | 2034 && r->request_body->temp_file |
2065 { | 2036 { |
2066 if (ngx_close_file(r->request_body->temp_file->file.fd) | 2037 if (ngx_close_file(r->request_body->temp_file->file.fd) |
2067 == NGX_FILE_ERROR) | 2038 == NGX_FILE_ERROR) |
2068 { | 2039 { |
2069 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 2040 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
2070 ngx_close_file_n " deleted file \"%s\" failed", | 2041 ngx_close_file_n " deleted file \"%V\" failed", |
2071 r->request_body->temp_file->file.name.data); | 2042 &r->request_body->temp_file->file.name); |
2072 } | 2043 } |
2073 } | 2044 } |
2074 | 2045 |
2075 if (r->connection->timedout) { | 2046 if (r->connection->timedout) { |
2076 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 2047 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2086 "setsockopt(SO_LINGER) failed"); | 2057 "setsockopt(SO_LINGER) failed"); |
2087 } | 2058 } |
2088 } | 2059 } |
2089 } | 2060 } |
2090 | 2061 |
2091 /* ctx->url was allocated from r->pool */ | 2062 /* the variuos request strings were allocated from r->pool */ |
2092 ctx = log->data; | 2063 ctx = log->data; |
2093 ctx->url = NULL; | 2064 ctx->request = NULL; |
2094 | 2065 |
2095 r->request_line.len = 0; | 2066 r->request_line.len = 0; |
2096 | 2067 |
2097 ngx_destroy_pool(r->pool); | 2068 ngx_destroy_pool(r->pool); |
2098 | 2069 |
2146 | 2117 |
2147 | 2118 |
2148 static void ngx_http_client_error(ngx_http_request_t *r, | 2119 static void ngx_http_client_error(ngx_http_request_t *r, |
2149 int client_error, int error) | 2120 int client_error, int error) |
2150 { | 2121 { |
2122 u_char *p; | |
2151 ngx_http_log_ctx_t *ctx; | 2123 ngx_http_log_ctx_t *ctx; |
2152 ngx_http_core_srv_conf_t *cscf; | 2124 ngx_http_core_srv_conf_t *cscf; |
2153 | 2125 |
2154 ctx = r->connection->log->data; | 2126 ctx = r->connection->log->data; |
2155 | 2127 |
2162 return; | 2134 return; |
2163 } | 2135 } |
2164 | 2136 |
2165 r->connection->log->handler = NULL; | 2137 r->connection->log->handler = NULL; |
2166 | 2138 |
2167 if (ctx->url) { | 2139 if (ctx->request) { |
2140 | |
2168 switch (client_error) { | 2141 switch (client_error) { |
2169 | 2142 |
2170 case NGX_HTTP_PARSE_INVALID_HOST: | 2143 case NGX_HTTP_PARSE_INVALID_HOST: |
2171 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 2144 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
2172 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], | 2145 "client %V sent invalid \"Host\" header \"%V\", URL: \"%V\"", |
2173 ctx->client, r->headers_in.host->value.data, ctx->url); | 2146 ctx->client, &r->headers_in.host->value, |
2147 &ctx->request->unparsed_uri); | |
2174 | 2148 |
2175 error = NGX_HTTP_INVALID_HOST; | 2149 error = NGX_HTTP_INVALID_HOST; |
2176 | 2150 |
2177 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 2151 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
2178 | 2152 |
2184 | 2158 |
2185 break; | 2159 break; |
2186 | 2160 |
2187 case NGX_HTTP_PARSE_HTTP_TO_HTTPS: | 2161 case NGX_HTTP_PARSE_HTTP_TO_HTTPS: |
2188 error = NGX_HTTP_TO_HTTPS; | 2162 error = NGX_HTTP_TO_HTTPS; |
2189 | 2163 if (ctx->request->headers_in.referer) { |
2190 /* fall through */ | 2164 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
2165 "client %V sent plain HTTP request to HTTPS port, " | |
2166 "URL: \"%V\", referrer \"%V\"", | |
2167 ctx->client, &ctx->request->unparsed_uri, | |
2168 &ctx->request->headers_in.referer->value); | |
2169 | |
2170 } else { | |
2171 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2172 "client %V sent plain HTTP request to HTTPS port, " | |
2173 "URL: \"%V\"", ctx->client, &ctx->request->unparsed_uri); | |
2174 } | |
2175 | |
2176 break; | |
2191 | 2177 |
2192 default: | 2178 default: |
2193 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 2179 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
2194 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], | 2180 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], |
2195 ctx->client, ctx->url); | 2181 ctx->client, &ctx->request->unparsed_uri); |
2196 } | 2182 } |
2197 | 2183 |
2198 } else { | 2184 } else { |
2185 | |
2199 if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { | 2186 if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { |
2200 r->request_line.len = r->header_in->end - r->request_start; | 2187 r->request_line.len = r->header_in->end - r->request_start; |
2201 r->request_line.data = r->request_start; | 2188 r->request_line.data = r->request_start; |
2189 | |
2190 } else { | |
2191 if (r->request_line.data == NULL) { | |
2192 for (p = r->request_start; p < r->header_in->last; p++) { | |
2193 if (*p == CR || *p == LF) { | |
2194 break; | |
2195 } | |
2196 } | |
2197 | |
2198 r->request_line.len = p - r->request_start; | |
2199 r->request_line.data = r->request_start; | |
2200 } | |
2202 } | 2201 } |
2203 | 2202 |
2204 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 2203 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
2205 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], | 2204 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], |
2206 ctx->client); | 2205 ctx->client, &r->request_line); |
2207 } | 2206 } |
2208 | 2207 |
2209 r->connection->log->handler = ngx_http_log_error; | 2208 r->connection->log->handler = ngx_http_log_error; |
2210 | 2209 |
2211 ngx_http_finalize_request(r, error); | 2210 ngx_http_finalize_request(r, error); |
2212 } | 2211 } |
2213 | 2212 |
2214 | 2213 |
2215 static size_t ngx_http_log_error(void *data, char *buf, size_t len) | 2214 static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len) |
2216 { | 2215 { |
2217 ngx_http_log_ctx_t *ctx = data; | 2216 ngx_http_log_ctx_t *ctx = data; |
2218 | 2217 |
2219 if (ctx->action && ctx->url) { | 2218 u_char *p; |
2220 return ngx_snprintf(buf, len, " while %s, client: %s, URL: %s", | 2219 |
2221 ctx->action, ctx->client, ctx->url); | 2220 p = buf; |
2222 | 2221 |
2223 } else if (ctx->action == NULL && ctx->url) { | 2222 if (ctx->action) { |
2224 return ngx_snprintf(buf, len, ", client: %s, URL: %s", | 2223 p = ngx_snprintf(p, len, " while %s", ctx->action); |
2225 ctx->client, ctx->url); | 2224 len -= p - buf; |
2226 | 2225 } |
2227 } else { | 2226 |
2228 return ngx_snprintf(buf, len, " while %s, client: %s", | 2227 p = ngx_snprintf(p, len, ", client: %V", ctx->client); |
2229 ctx->action, ctx->client); | 2228 |
2230 } | 2229 if (ctx->request == NULL) { |
2231 } | 2230 return p; |
2231 } | |
2232 | |
2233 len -= p - buf; | |
2234 | |
2235 p = ngx_snprintf(p, len, ", URL: \"%V\"", &ctx->request->unparsed_uri); | |
2236 | |
2237 if (ctx->request->headers_in.referer == NULL) { | |
2238 return p; | |
2239 } | |
2240 | |
2241 len -= p - buf; | |
2242 | |
2243 return ngx_snprintf(p, len, ", referrer: \"%V\"", | |
2244 &ctx->request->headers_in.referer->value); | |
2245 } |