# HG changeset patch # User Igor Sysoev # Date 1084553507 0 # Node ID d4241d7787fe8539f08c70a6d472fa2de48ddf8d # Parent af451db3fe99e2aa85c47e708f61afc55c098ca1 nginx-0.0.3-2004-05-14-20:51:47 import diff -r af451db3fe99 -r d4241d7787fe src/http/modules/ngx_http_gzip_filter.c --- a/src/http/modules/ngx_http_gzip_filter.c Wed May 12 05:37:55 2004 +0000 +++ b/src/http/modules/ngx_http_gzip_filter.c Fri May 14 16:51:47 2004 +0000 @@ -18,7 +18,7 @@ int level; size_t wbits; size_t memlevel; - size_t min_length; + ssize_t min_length; } ngx_http_gzip_conf_t; @@ -913,7 +913,7 @@ ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS); ngx_conf_merge_size_value(conf->memlevel, prev->memlevel, MAX_MEM_LEVEL - 1); - ngx_conf_merge_size_value(conf->min_length, prev->min_length, 0); + ngx_conf_merge_value(conf->min_length, prev->min_length, 0); ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0); return NGX_CONF_OK; diff -r af451db3fe99 -r d4241d7787fe src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c Wed May 12 05:37:55 2004 +0000 +++ b/src/http/modules/ngx_http_range_filter.c Fri May 14 16:51:47 2004 +0000 @@ -114,17 +114,6 @@ || r->headers_out.status != NGX_HTTP_OK || r->headers_out.content_length_n == -1 || !(r->filter & NGX_HTTP_FILTER_ALLOW_RANGES)) - -#if 0 - /* STUB: we currently support ranges for file hunks only */ - || !r->sendfile - || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY -#endif - -#if 0 - || (r->headers_out.content_encoding - && r->headers_out.content_encoding->value.len)) -#endif { return ngx_http_next_header_filter(r); } @@ -506,8 +495,7 @@ return ngx_http_next_body_filter(r, out); } - /* TODO: several incoming hunks of proxied responses - and memory hunks on platforms that have no sendfile() */ + /* TODO: alert */ return ngx_http_next_body_filter(r, in); } diff -r af451db3fe99 -r d4241d7787fe src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c Wed May 12 05:37:55 2004 +0000 +++ b/src/http/ngx_http_core_module.c Fri May 14 16:51:47 2004 +0000 @@ -37,6 +37,14 @@ static ngx_conf_post_t ngx_http_lowat_post = { ngx_http_lowat_check } ; +static ngx_conf_enum_t ngx_http_restrict_host_names[] = { + { ngx_string("off"), NGX_HTTP_RESTRICT_HOST_OFF }, + { ngx_string("on"), NGX_HTTP_RESTRICT_HOST_ON }, + { ngx_string("close"), NGX_HTTP_RESTRICT_HOST_CLOSE }, + { ngx_null_string, 0 } +}; + + static ngx_command_t ngx_http_core_commands[] = { { ngx_string("server"), @@ -88,6 +96,13 @@ offsetof(ngx_http_core_srv_conf_t, large_client_header), NULL }, + { ngx_string("restrict_host_names"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_enum_slot, + NGX_HTTP_SRV_CONF_OFFSET, + offsetof(ngx_http_core_srv_conf_t, restrict_host_names), + &ngx_http_restrict_host_names }, + { ngx_string("location"), NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12, ngx_location_block, @@ -1127,6 +1142,7 @@ cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; cscf->large_client_header = NGX_CONF_UNSET; + cscf->restrict_host_names = NGX_CONF_UNSET_UINT; return cscf; } @@ -1182,6 +1198,8 @@ prev->client_header_buffer_size, 1024); ngx_conf_merge_value(conf->large_client_header, prev->large_client_header, 1); + ngx_conf_merge_unsigned_value(conf->restrict_host_names, + prev->restrict_host_names, 0); return NGX_CONF_OK; } diff -r af451db3fe99 -r d4241d7787fe src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h Wed May 12 05:37:55 2004 +0000 +++ b/src/http/ngx_http_core_module.h Fri May 14 16:51:47 2004 +0000 @@ -58,6 +58,8 @@ ngx_msec_t post_accept_timeout; ngx_msec_t client_header_timeout; + ngx_uint_t restrict_host_names; + ngx_flag_t large_client_header; } ngx_http_core_srv_conf_t; diff -r af451db3fe99 -r d4241d7787fe src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c Wed May 12 05:37:55 2004 +0000 +++ b/src/http/ngx_http_request.c Fri May 14 16:51:47 2004 +0000 @@ -39,7 +39,8 @@ "client %s sent too long header line, URL: %s", "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", "client %s sent invalid \"Content-Length\" header, URL: %s", - "client %s sent POST method without \"Content-Length\" header, URL: %s" + "client %s sent POST method without \"Content-Length\" header, URL: %s", + "client %s sent invalid \"Host\" header \"%s\", URL: %s" }; @@ -847,6 +848,7 @@ size_t len; ngx_uint_t i; ngx_http_server_name_t *name; + ngx_http_core_srv_conf_t *cscf; ngx_http_core_loc_conf_t *clcf; if (r->headers_in.host) { @@ -881,6 +883,14 @@ } } + if (i == r->virtual_names->nelts) { + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + + if (cscf->restrict_host_names != NGX_HTTP_RESTRICT_HOST_OFF) { + return NGX_HTTP_PARSE_INVALID_HOST; + } + } + } else { if (r->http_version > NGX_HTTP_VERSION_10) { return NGX_HTTP_PARSE_NO_HOST_HEADER; @@ -1653,7 +1663,8 @@ static void ngx_http_client_error(ngx_http_request_t *r, int client_error, int error) { - ngx_http_log_ctx_t *ctx; + ngx_http_log_ctx_t *ctx; + ngx_http_core_srv_conf_t *cscf; ctx = r->connection->log->data; @@ -1668,9 +1679,26 @@ r->connection->log->handler = NULL; if (ctx->url) { - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + if (client_error == NGX_HTTP_PARSE_INVALID_HOST) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], + ctx->client, r->headers_in.host->value.data, ctx->url); + + error = NGX_HTTP_INVALID_HOST; + + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + + if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_CLOSE) { + ngx_http_close_request(r, error); + ngx_http_close_connection(r->connection); + return; + } + + } else { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], ctx->client, ctx->url); + } } else { if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { diff -r af451db3fe99 -r d4241d7787fe src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h Wed May 12 05:37:55 2004 +0000 +++ b/src/http/ngx_http_request.h Fri May 14 16:51:47 2004 +0000 @@ -31,6 +31,7 @@ #define NGX_HTTP_PARSE_NO_HOST_HEADER 16 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18 +#define NGX_HTTP_PARSE_INVALID_HOST 19 #define NGX_HTTP_OK 200 @@ -50,6 +51,17 @@ #define NGX_HTTP_REQUEST_URI_TOO_LARGE 414 #define NGX_HTTP_RANGE_NOT_SATISFIABLE 416 + +/* Our own HTTP codes */ + +#define NGX_HTTP_NGX_CODES NGX_HTTP_INVALID_HOST + +/* + * We use the special code for the requests with invalid host name + * to distinguish it from 4XX in an error page redirection + */ +#define NGX_HTTP_INVALID_HOST 498 + /* * HTTP does not define the code for the case when a client closed * the connection while we are processing its request so we introduce @@ -58,6 +70,7 @@ */ #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499 + #define NGX_HTTP_INTERNAL_SERVER_ERROR 500 #define NGX_HTTP_NOT_IMPLEMENTED 501 #define NGX_HTTP_BAD_GATEWAY 502 @@ -66,6 +79,13 @@ typedef enum { + NGX_HTTP_RESTRICT_HOST_OFF = 0, + NGX_HTTP_RESTRICT_HOST_ON, + NGX_HTTP_RESTRICT_HOST_CLOSE +} ngx_http_restrict_host_e; + + +typedef enum { NGX_HTTP_INITING_REQUEST_STATE = 0, NGX_HTTP_READING_REQUEST_STATE, NGX_HTTP_PROCESS_REQUEST_STATE, diff -r af451db3fe99 -r d4241d7787fe src/http/ngx_http_special_response.c --- a/src/http/ngx_http_special_response.c Wed May 12 05:37:55 2004 +0000 +++ b/src/http/ngx_http_special_response.c Fri May 14 16:51:47 2004 +0000 @@ -166,6 +166,9 @@ ngx_null_string, /* 415 */ ngx_string(error_416_page), + ngx_string(error_404_page), /* 498 */ + ngx_null_string, /* 499 */ + ngx_string(error_500_page), ngx_string(error_501_page), ngx_string(error_502_page), @@ -229,13 +232,20 @@ /* 3XX */ err = error - NGX_HTTP_MOVED_PERMANENTLY; - } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) { + } else if (error < NGX_HTTP_NGX_CODES) { /* 4XX */ err = error - NGX_HTTP_BAD_REQUEST + 3; } else { - /* 5XX */ - err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17; + /* 49X, 5XX */ + err = error - NGX_HTTP_NGX_CODES + 3 + 17; + + switch (error) { + case NGX_HTTP_INVALID_HOST: + r->headers_out.status = NGX_HTTP_NOT_FOUND; + error = NGX_HTTP_NOT_FOUND; + break; + } } if (error_pages[err].len) {