aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-05-14 16:51:47 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-05-14 16:51:47 +0000
commit3043bfcf105e47969720d5bce8c3a89afe8e666d (patch)
treeb96e067363d329f55db34a53d76e6717108d630f /src
parent31f7f6a5410c258e9ad85a4b166804bc57b4c0b9 (diff)
downloadnginx-3043bfcf105e47969720d5bce8c3a89afe8e666d.tar.gz
nginx-3043bfcf105e47969720d5bce8c3a89afe8e666d.zip
nginx-0.0.3-2004-05-14-20:51:47 import
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_gzip_filter.c4
-rw-r--r--src/http/modules/ngx_http_range_filter.c14
-rw-r--r--src/http/ngx_http_core_module.c18
-rw-r--r--src/http/ngx_http_core_module.h2
-rw-r--r--src/http/ngx_http_request.c34
-rw-r--r--src/http/ngx_http_request.h20
-rw-r--r--src/http/ngx_http_special_response.c16
7 files changed, 87 insertions, 21 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index b7b5abf96..76b07bfb5 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -18,7 +18,7 @@ typedef struct {
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 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
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 --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index d63f4c8d5..ecb42ad3d 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -114,17 +114,6 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
|| 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 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
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 --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index b8e1a195d..73a114ac5 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -37,6 +37,14 @@ static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data);
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 @@ static ngx_command_t ngx_http_core_commands[] = {
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 @@ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf)
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 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
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 --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 40cf40f0d..a8a6cf0ef 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -58,6 +58,8 @@ typedef struct {
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 --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index a8c4aeed2..25cc295ee 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -39,7 +39,8 @@ static char *client_header_errors[] = {
"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 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
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 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
}
}
+ 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 @@ void ngx_http_close_connection(ngx_connection_t *c)
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 @@ static void ngx_http_client_error(ngx_http_request_t *r,
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 --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 716818fa4..8013ef840 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -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 --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 55f4bb3ac..48963464a 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -166,6 +166,9 @@ static ngx_str_t error_pages[] = {
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 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
/* 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) {