Mercurial > hg > nginx-vendor-0-8
comparison src/http/ngx_http_core_module.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 | 7da8ea7c4448 |
comparison
equal
deleted
inserted
replaced
9:77eee314ddbd | 10:46833bd150cb |
---|---|
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 #include <nginx.h> | 11 #include <nginx.h> |
12 | 12 |
13 /* STUB */ | 13 |
14 #define NGX_HTTP_LOCATION_EXACT 1 | 14 #define NGX_HTTP_LOCATION_EXACT 1 |
15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 | 15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 |
16 #define NGX_HTTP_LOCATION_REGEX 3 | 16 #define NGX_HTTP_LOCATION_REGEX 3 |
17 | 17 |
18 | 18 |
327 }; | 327 }; |
328 | 328 |
329 | 329 |
330 void ngx_http_handler(ngx_http_request_t *r) | 330 void ngx_http_handler(ngx_http_request_t *r) |
331 { | 331 { |
332 ngx_http_log_ctx_t *lcx; | 332 ngx_http_log_ctx_t *ctx; |
333 | 333 |
334 r->connection->unexpected_eof = 0; | 334 r->connection->unexpected_eof = 0; |
335 | 335 |
336 lcx = r->connection->log->data; | 336 ctx = r->connection->log->data; |
337 lcx->action = NULL; | 337 ctx->action = NULL; |
338 | 338 |
339 switch (r->headers_in.connection_type) { | 339 switch (r->headers_in.connection_type) { |
340 case 0: | 340 case 0: |
341 if (r->http_version > NGX_HTTP_VERSION_10) { | 341 if (r->http_version > NGX_HTTP_VERSION_10) { |
342 r->keepalive = 1; | 342 r->keepalive = 1; |
524 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; | 524 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
525 } | 525 } |
526 | 526 |
527 | 527 |
528 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 528 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
529 "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, | 529 "http cl:%z max:%uz", |
530 r->headers_in.content_length_n, | 530 r->headers_in.content_length_n, clcf->client_max_body_size); |
531 clcf->client_max_body_size); | |
532 | 531 |
533 if (r->headers_in.content_length_n != -1 | 532 if (r->headers_in.content_length_n != -1 |
534 && clcf->client_max_body_size | 533 && clcf->client_max_body_size |
535 && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) | 534 && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) |
536 { | 535 { |
537 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 536 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
538 "client intented to send too large body: " | 537 "client intented to send too large body: %z bytes", |
539 SIZE_T_FMT " bytes", | |
540 r->headers_in.content_length_n); | 538 r->headers_in.content_length_n); |
541 | 539 |
542 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; | 540 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; |
543 } | 541 } |
544 | 542 |
581 break; | 579 break; |
582 } | 580 } |
583 #endif | 581 #endif |
584 | 582 |
585 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 583 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
586 "find location: %s\"%s\"", | 584 "find location: %s\"%V\"", |
587 clcfp[i]->exact_match ? "= " : "", | 585 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name); |
588 clcfp[i]->name.data); | |
589 | 586 |
590 if (clcfp[i]->auto_redirect | 587 if (clcfp[i]->auto_redirect |
591 && r->uri.len == clcfp[i]->name.len - 1 | 588 && r->uri.len == clcfp[i]->name.len - 1 |
592 && ngx_strncmp(r->uri.data, clcfp[i]->name.data, | 589 && ngx_strncmp(r->uri.data, clcfp[i]->name.data, |
593 clcfp[i]->name.len - 1) == 0) | 590 clcfp[i]->name.len - 1) == 0) |
647 if (!clcfp[i]->regex) { | 644 if (!clcfp[i]->regex) { |
648 continue; | 645 continue; |
649 } | 646 } |
650 | 647 |
651 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 648 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
652 "find location: ~ \"%s\"", | 649 "find location: ~ \"%V\"", &clcfp[i]->name); |
653 clcfp[i]->name.data); | |
654 | 650 |
655 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); | 651 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); |
656 | 652 |
657 if (n == NGX_DECLINED) { | 653 if (n == NGX_DECLINED) { |
658 continue; | 654 continue; |
659 } | 655 } |
660 | 656 |
661 if (n < 0) { | 657 if (n < 0) { |
662 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 658 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
663 ngx_regex_exec_n | 659 ngx_regex_exec_n |
664 " failed: %d on \"%s\" using \"%s\"", | 660 " failed: %d on \"%V\" using \"%V\"", |
665 n, r->uri.data, clcfp[i]->name.data); | 661 n, &r->uri, &clcfp[i]->name); |
666 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 662 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
667 } | 663 } |
668 | 664 |
669 /* match */ | 665 /* match */ |
670 | 666 |
807 | 803 |
808 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, | 804 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, |
809 ngx_str_t *uri, ngx_str_t *args) | 805 ngx_str_t *uri, ngx_str_t *args) |
810 { | 806 { |
811 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 807 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
812 "internal redirect: \"%s\"", uri->data); | 808 "internal redirect: \"%V\"", uri); |
813 | 809 |
814 r->uri.len = uri->len; | 810 r->uri = *uri; |
815 r->uri.data = uri->data; | |
816 | 811 |
817 if (args) { | 812 if (args) { |
818 r->args.len = args->len; | 813 r->args = *args; |
819 r->args.data = args->data; | |
820 } | 814 } |
821 | 815 |
822 if (ngx_http_set_exten(r) != NGX_OK) { | 816 if (ngx_http_set_exten(r) != NGX_OK) { |
823 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 817 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
824 } | 818 } |
1090 } | 1084 } |
1091 | 1085 |
1092 clcf->name = value[2]; | 1086 clcf->name = value[2]; |
1093 #else | 1087 #else |
1094 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1088 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1095 "the using of the regex \"%s\" " | 1089 "the using of the regex \"%V\" " |
1096 "requires PCRE library", | 1090 "requires PCRE library", &value[2]); |
1097 value[2].data); | |
1098 return NGX_CONF_ERROR; | 1091 return NGX_CONF_ERROR; |
1099 #endif | 1092 #endif |
1100 | 1093 |
1101 } else { | 1094 } else { |
1102 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1095 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1103 "invalid location modifier \"%s\"", | 1096 "invalid location modifier \"%V\"", &value[1]); |
1104 value[1].data); | |
1105 return NGX_CONF_ERROR; | 1097 return NGX_CONF_ERROR; |
1106 } | 1098 } |
1107 | 1099 |
1108 } else { | 1100 } else { |
1109 clcf->name.len = value[1].len; | 1101 clcf->name.len = value[1].len; |
1121 } else { | 1113 } else { |
1122 clcf->prev_location = pclcf; | 1114 clcf->prev_location = pclcf; |
1123 | 1115 |
1124 if (pclcf->exact_match) { | 1116 if (pclcf->exact_match) { |
1125 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1117 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1126 "location \"%s\" could not be inside " | 1118 "location \"%V\" could not be inside " |
1127 "the exact location \"%s\"", | 1119 "the exact location \"%V\"", |
1128 clcf->name.data, pclcf->name.data); | 1120 &clcf->name, &pclcf->name); |
1129 return NGX_CONF_ERROR; | 1121 return NGX_CONF_ERROR; |
1130 } | 1122 } |
1131 | 1123 |
1132 #if (NGX_PCRE) | 1124 #if (NGX_PCRE) |
1133 if (clcf->regex == NULL | 1125 if (clcf->regex == NULL |
1137 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len) | 1129 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len) |
1138 != 0) | 1130 != 0) |
1139 #endif | 1131 #endif |
1140 { | 1132 { |
1141 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1133 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1142 "location \"%s\" is outside location \"%s\"", | 1134 "location \"%V\" is outside location \"%V\"", |
1143 clcf->name.data, pclcf->name.data); | 1135 &clcf->name, &pclcf->name); |
1144 return NGX_CONF_ERROR; | 1136 return NGX_CONF_ERROR; |
1145 } | 1137 } |
1146 | 1138 |
1147 if (pclcf->locations.elts == NULL) { | 1139 if (pclcf->locations.elts == NULL) { |
1148 ngx_init_array(pclcf->locations, cf->pool, 5, sizeof(void *), | 1140 ngx_init_array(pclcf->locations, cf->pool, 5, sizeof(void *), |
1299 /* TODO: it does not merge, it inits only */ | 1291 /* TODO: it does not merge, it inits only */ |
1300 | 1292 |
1301 if (conf->listen.nelts == 0) { | 1293 if (conf->listen.nelts == 0) { |
1302 ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); | 1294 ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); |
1303 l->addr = INADDR_ANY; | 1295 l->addr = INADDR_ANY; |
1304 #if (WIN32) | 1296 #if (NGX_WIN32) |
1305 l->port = 80; | 1297 l->port = 80; |
1306 #else | 1298 #else |
1307 /* STUB: getuid() should be cached */ | 1299 /* STUB: getuid() should be cached */ |
1308 l->port = (getuid() == 0) ? 80 : 8000; | 1300 l->port = (getuid() == 0) ? 80 : 8000; |
1309 #endif | 1301 #endif |
1559 | 1551 |
1560 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ | 1552 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ |
1561 || (port < 1 || port > 65536)) { /* "listen 99999" */ | 1553 || (port < 1 || port > 65536)) { /* "listen 99999" */ |
1562 | 1554 |
1563 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1555 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1564 "invalid port \"%s\" in \"%s\" directive, " | 1556 "invalid port \"%s\" in \"%V\" directive, " |
1565 "it must be a number between 1 and 65535", | 1557 "it must be a number between 1 and 65535", |
1566 &addr[p], cmd->name.data); | 1558 &addr[p], &cmd->name); |
1567 | 1559 |
1568 return NGX_CONF_ERROR; | 1560 return NGX_CONF_ERROR; |
1569 | 1561 |
1570 } else if (p == 0) { | 1562 } else if (p == 0) { |
1571 ls->addr = INADDR_ANY; | 1563 ls->addr = INADDR_ANY; |
1581 h = gethostbyname((const char *) addr); | 1573 h = gethostbyname((const char *) addr); |
1582 | 1574 |
1583 if (h == NULL || h->h_addr_list[0] == NULL) { | 1575 if (h == NULL || h->h_addr_list[0] == NULL) { |
1584 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1576 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1585 "can not resolve host \"%s\" " | 1577 "can not resolve host \"%s\" " |
1586 "in \"%s\" directive", addr, cmd->name.data); | 1578 "in \"%V\" directive", addr, &cmd->name); |
1587 return NGX_CONF_ERROR; | 1579 return NGX_CONF_ERROR; |
1588 } | 1580 } |
1589 | 1581 |
1590 ls->addr = *(in_addr_t *)(h->h_addr_list[0]); | 1582 ls->addr = *(in_addr_t *)(h->h_addr_list[0]); |
1591 } | 1583 } |
1610 value = cf->args->elts; | 1602 value = cf->args->elts; |
1611 | 1603 |
1612 for (i = 1; i < cf->args->nelts; i++) { | 1604 for (i = 1; i < cf->args->nelts; i++) { |
1613 if (value[i].len == 0) { | 1605 if (value[i].len == 0) { |
1614 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1606 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1615 "server name \"%s\" is invalid " | 1607 "server name \"%V\" is invalid " |
1616 "in \"%s\" directive", | 1608 "in \"%V\" directive", |
1617 value[i].data, cmd->name.data); | 1609 &value[i], &cmd->name); |
1618 return NGX_CONF_ERROR; | 1610 return NGX_CONF_ERROR; |
1619 } | 1611 } |
1620 | 1612 |
1621 if (!(sn = ngx_array_push(&scf->server_names))) { | 1613 if (!(sn = ngx_array_push(&scf->server_names))) { |
1622 return NGX_CONF_ERROR; | 1614 return NGX_CONF_ERROR; |
1657 | 1649 |
1658 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ | 1650 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ |
1659 | 1651 |
1660 if ((ngx_uint_t) lcf->alias == alias) { | 1652 if ((ngx_uint_t) lcf->alias == alias) { |
1661 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1653 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1662 "\"%s\" directive is duplicate", | 1654 "\"%V\" directive is duplicate", |
1663 cmd->name.data); | 1655 &cmd->name); |
1664 } else { | 1656 } else { |
1665 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1657 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1666 "\"%s\" directive is duplicate, " | 1658 "\"%V\" directive is duplicate, " |
1667 "\"%s\" directive is specified before", | 1659 "\"%s\" directive is specified before", |
1668 cmd->name.data, lcf->alias ? "alias" : "root"); | 1660 &cmd->name, lcf->alias ? "alias" : "root"); |
1669 } | 1661 } |
1670 | 1662 |
1671 return NGX_CONF_ERROR; | 1663 return NGX_CONF_ERROR; |
1672 } | 1664 } |
1673 | 1665 |
1706 i = cf->args->nelts - 2; | 1698 i = cf->args->nelts - 2; |
1707 | 1699 |
1708 if (value[i].data[0] == '=') { | 1700 if (value[i].data[0] == '=') { |
1709 if (i == 1) { | 1701 if (i == 1) { |
1710 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1702 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1711 "invalid value \"%s\"", value[i].data); | 1703 "invalid value \"%V\"", &value[i]); |
1712 return NGX_CONF_ERROR; | 1704 return NGX_CONF_ERROR; |
1713 } | 1705 } |
1714 | 1706 |
1715 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1); | 1707 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1); |
1716 | 1708 |
1717 if (overwrite == NGX_ERROR) { | 1709 if (overwrite == NGX_ERROR) { |
1718 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1710 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1719 "invalid value \"%s\"", value[i].data); | 1711 "invalid value \"%V\"", value[i]); |
1720 return NGX_CONF_ERROR; | 1712 return NGX_CONF_ERROR; |
1721 } | 1713 } |
1722 | 1714 |
1723 n = 2; | 1715 n = 2; |
1724 | 1716 |
1733 } | 1725 } |
1734 | 1726 |
1735 err->status = ngx_atoi(value[i].data, value[i].len); | 1727 err->status = ngx_atoi(value[i].data, value[i].len); |
1736 if (err->status == NGX_ERROR) { | 1728 if (err->status == NGX_ERROR) { |
1737 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1729 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1738 "invalid value \"%s\"", value[i].data); | 1730 "invalid value \"%V\"", &value[i]); |
1739 return NGX_CONF_ERROR; | 1731 return NGX_CONF_ERROR; |
1740 } | 1732 } |
1741 | 1733 |
1742 if (err->status < 400 || err->status > 599) { | 1734 if (err->status < 400 || err->status > 599) { |
1743 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1735 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1744 "value \"%s\" must be between 400 and 599", | 1736 "value \"%V\" must be between 400 and 599", |
1745 value[i].data); | 1737 &value[i]); |
1746 return NGX_CONF_ERROR; | 1738 return NGX_CONF_ERROR; |
1747 } | 1739 } |
1748 | 1740 |
1749 err->overwrite = overwrite; | 1741 err->overwrite = overwrite; |
1750 err->uri = value[cf->args->nelts - 1]; | 1742 err->uri = value[cf->args->nelts - 1]; |