summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES50
-rw-r--r--CHANGES.ru51
-rw-r--r--auto/modules5
-rw-r--r--auto/options3
-rw-r--r--auto/sources1
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_hash.c79
-rw-r--r--src/core/ngx_times.c39
-rw-r--r--src/core/ngx_times.h3
-rw-r--r--src/event/ngx_event_openssl.c3
-rw-r--r--src/http/modules/ngx_http_addition_filter_module.c42
-rw-r--r--src/http/modules/ngx_http_charset_filter_module.c46
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c109
-rw-r--r--src/http/modules/ngx_http_headers_filter_module.c39
-rw-r--r--src/http/modules/ngx_http_index_module.c17
-rw-r--r--src/http/modules/ngx_http_ssi_filter_module.c113
-rw-r--r--src/http/modules/ngx_http_sub_filter_module.c116
-rw-r--r--src/http/modules/ngx_http_xslt_filter_module.c299
-rw-r--r--src/http/modules/perl/nginx.pm2
-rw-r--r--src/http/ngx_http.c6
-rw-r--r--src/http/ngx_http.h2
-rw-r--r--src/mail/ngx_mail_handler.c2
-rw-r--r--src/misc/ngx_cpp_test_module.cpp27
23 files changed, 626 insertions, 430 deletions
diff --git a/CHANGES b/CHANGES
index 93d77163a..e48185b18 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,48 @@
+Changes with nginx 0.7.9 12 Aug 2008
+
+ *) Change: now ngx_http_charset_module works by default with following
+ MIME types: text/html, text/css, text/xml, text/plain,
+ text/vnd.wap.wml, application/x-javascript, and application/rss+xml.
+
+ *) Feature: the "charset_types" and "addition_types" directives.
+
+ *) Feature: now the "gzip_types", "ssi_types", and "sub_filter_types"
+ directives use hash.
+
+ *) Feature: the ngx_cpp_test_module.
+
+ *) Feature: the "expires" directive supports daily time.
+
+ *) Feature: the ngx_http_xslt_module improvements and bug fixing.
+ Thanks to Denis F. Latypoff and Maxim Dounin.
+
+ *) Bugfix: the "log_not_found" directive did not work for index files
+ tests.
+
+ *) Bugfix: HTTPS connections might hang, if kqueue, epoll, rtsig, or
+ eventport methods were used; the bug had appeared in 0.7.7.
+
+ *) Bugfix: if the "server_name", "valid_referers", and "map" directives
+ used an "*.domain.tld" wildcard and exact name "domain.tld" was not
+ set, then the exact name was matched by the wildcard; the bugs had
+ appeared in 0.3.18.
+
+
+Changes with nginx 0.7.8 04 Aug 2008
+
+ *) Feature: the ngx_http_xslt_module.
+
+ *) Feature: the "$arg_..." variables.
+
+ *) Feature: Solaris directio support.
+ Thanks to Ivan Debnar.
+
+ *) Bugfix: now if FastCGI server sends a "Location" header line without
+ status line, then nginx uses 302 status code.
+ Thanks to Maxim Dounin.
+
+
Changes with nginx 0.7.7 30 Jul 2008
*) Change: now the EAGAIN error returned by connect() is not considered
@@ -15,8 +59,9 @@ Changes with nginx 0.7.7 30 Jul 2008
Thanks to Maxim Dounin.
*) Feature: the "directio" directive.
+ Thanks to Jiang Hong.
- *) Feature: MacOSX 1.5 sendfile() support.
+ *) Feature: MacOSX 10.5 sendfile() support.
*) Bugfix: now in MacOSX and Cygwin locations are tested in case
insensitive mode; however, the compare is provided by single-byte
@@ -375,8 +420,7 @@ Changes with nginx 0.6.22 19 Dec 2007
Changes with nginx 0.6.21 03 Dec 2007
*) Change: if variable values used in a "proxy_pass" directive contain
- IP-addresses only, then a "resolver" directive is not mandatory.
- resolver
+ IP-addresses only, then a "resolver" directive is not mandatory.
*) Bugfix: a segmentation fault might occur in worker process if a
"proxy_pass" directive with URI-part was used; the bug had appeared
diff --git a/CHANGES.ru b/CHANGES.ru
index 7eb6402b0..40112f44a 100644
--- a/CHANGES.ru
+++ b/CHANGES.ru
@@ -1,4 +1,50 @@
+Изменения в nginx 0.7.9 12.08.2008
+
+ *) Изменение: теперь ngx_http_charset_module по умолчанию работает со
+ следующими MIME-типами: text/html, text/css, text/xml, text/plain,
+ text/vnd.wap.wml, application/x-javascript и application/rss+xml.
+
+ *) Добавление: директивы charset_types и addition_types.
+
+ *) Добавление: теперь директивы gzip_types, ssi_types и
+ sub_filter_types используют хэш.
+
+ *) Добавление: модуль ngx_cpp_test_module.
+
+ *) Добавление: директива expires поддерживает суточное время.
+
+ *) Добавление: улучшения и исправления в модуле
+ ngx_http_xslt_module.
+ Спасибо Денису Латыпову и Максиму Дунину.
+
+ *) Исправление: директива log_not_found не работала при поиске
+ индексных файлов.
+
+ *) Исправление: HTTPS-соединения могли зависнуть, если использовались
+ методы kqueue, epoll, rtsig или eventport; ошибка появилась в 0.7.7.
+
+ *) Исправление: если в директивах server_name, valid_referers и map
+ использовалась маска вида "*.domain.tld" и при этом полное имя вида
+ "domain.tld" не было описано, то это имя попадало под маску; ошибка
+ появилась в 0.3.18.
+
+
+Изменения в nginx 0.7.8 04.08.2008
+
+ *) Добавление: модуль ngx_http_xslt_module.
+
+ *) Добавление: переменные "$arg_...".
+
+ *) Добавление: поддержка directio в Solaris.
+ Спасибо Ivan Debnar.
+
+ *) Исправление: теперь, если FastCGI-сервер присылает строку "Location"
+ в заголовке ответа без строки статуса, то nginx использует код
+ статуса 302.
+ Спасибо Максиму Дунину.
+
+
Изменения в nginx 0.7.7 30.07.2008
*) Изменение: теперь ошибка EAGAIN при вызове connect() не считается
@@ -15,8 +61,9 @@
Спасибо Максиму Дунину.
*) Добавление: директива directio.
+ Спасибо Jiang Hong.
- *) Добавление: поддержка sendfile() в MacOSX 1.5.
+ *) Добавление: поддержка sendfile() в MacOSX 10.5.
*) Исправление: в MacOSX и Cygwin при проверке location'ов теперь
делается сравнение без учёта регистра символов; однако, сравнение
@@ -41,7 +88,7 @@
Изменения в nginx 0.7.5 01.07.2008
*) Исправления в поддержке переменных в директиве access_log; ошибки
- появилась в 0.7.4.
+ появились в 0.7.4.
*) Исправление: nginx не собирался с параметром
--without-http_gzip_module; ошибка появилась в 0.7.3.
diff --git a/auto/modules b/auto/modules
index 0c2a36787..36ed53f5b 100644
--- a/auto/modules
+++ b/auto/modules
@@ -392,6 +392,11 @@ if [ $NGX_GOOGLE_PERFTOOLS = YES ]; then
fi
+if [ $NGX_CPP_TEST_MODULE = YES ]; then
+ NGX_MISC_SRCS="$NGX_MISC_SRCS $NGX_CPP_TEST_SRCS"
+fi
+
+
cat << END > $NGX_MODULES_C
#include <ngx_config.h>
diff --git a/auto/options b/auto/options
index 1498243bb..b99e904ed 100644
--- a/auto/options
+++ b/auto/options
@@ -119,6 +119,7 @@ NGX_PERL=perl
USE_LIBXSLT=NO
NGX_GOOGLE_PERFTOOLS=NO
+NGX_CPP_TEST=NO
NGX_CPU_CACHE_LINE=
@@ -208,6 +209,7 @@ do
--without-mail_smtp_module) MAIL_SMTP=NO ;;
--with-google_perftools_module) NGX_GOOGLE_PERFTOOLS=YES ;;
+ --with-cpp_test_module) NGX_CPP_TEST_MODULE=YES ;;
--add-module=*) NGX_ADDONS="$NGX_ADDONS $value" ;;
@@ -327,6 +329,7 @@ cat << END
--without-mail_smtp_module disable ngx_mail_smtp_module
--with-google_perftools_module enable ngx_google_perftools_module
+ --with-cpp_test_module enable ngx_cpp_test_module
--add-module=PATH enable an external module
diff --git a/auto/sources b/auto/sources
index 82734ddb9..66859ae42 100644
--- a/auto/sources
+++ b/auto/sources
@@ -474,3 +474,4 @@ MAIL_PROXY_SRCS="src/mail/ngx_mail_proxy_module.c"
NGX_GOOGLE_PERFTOOLS_MODULE=ngx_google_perftools_module
NGX_GOOGLE_PERFTOOLS_SRCS=src/misc/ngx_google_perftools_module.c
+NGX_CPP_TEST_SRCS=src/misc/ngx_cpp_test_module.cpp
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 576c7feaa..747fee6d9 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VERSION "0.7.8"
+#define NGINX_VERSION "0.7.9"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"
diff --git a/src/core/ngx_hash.c b/src/core/ngx_hash.c
index 2954266ae..d36b142b9 100644
--- a/src/core/ngx_hash.c
+++ b/src/core/ngx_hash.c
@@ -15,11 +15,7 @@ ngx_hash_find(ngx_hash_t *hash, ngx_uint_t key, u_char *name, size_t len)
ngx_hash_elt_t *elt;
#if 0
- ngx_str_t line;
-
- line.len = len;
- line.data = name;
- ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "hf:\"%V\"", &line);
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "hf:\"%*s\"", len, name);
#endif
elt = hash->buckets[key % hash->size];
@@ -59,11 +55,7 @@ ngx_hash_find_wc_head(ngx_hash_wildcard_t *hwc, u_char *name, size_t len)
ngx_uint_t i, n, key;
#if 0
- ngx_str_t line;
-
- line.len = len;
- line.data = name;
- ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "wch:\"%V\"", &line);
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "wch:\"%*s\"", len, name);
#endif
n = len;
@@ -88,30 +80,40 @@ ngx_hash_find_wc_head(ngx_hash_wildcard_t *hwc, u_char *name, size_t len)
value = ngx_hash_find(&hwc->hash, key, &name[n], len - n);
+#if 0
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "value:\"%p\"", value);
+#endif
+
if (value) {
/*
* the 2 low bits of value have the special meaning:
- * 00 - value is data pointer,
- * 01 - value is pointer to wildcard hash allowing
- * "*.example.com" only,
+ * 00 - value is data pointer for both "example.com"
+ * and "*.example.com";
+ * 01 - value is data pointer for "*.example.com" only;
+ * 10 - value is pointer to wildcard hash allowing
+ * both "example.com" and "*.example.com";
* 11 - value is pointer to wildcard hash allowing
- * both "example.com" and "*.example.com".
+ * "*.example.com" only.
*/
- if ((uintptr_t) value & 1) {
-
- hwc = (ngx_hash_wildcard_t *) ((uintptr_t) value & (uintptr_t) ~3);
+ if ((uintptr_t) value & 2) {
if (n == 0) {
- if ((uintptr_t) value & 2) {
- return hwc->value;
- } else {
+ /* "example.com" */
+
+ if ((uintptr_t) value & 1) {
return NULL;
}
+
+ hwc = (ngx_hash_wildcard_t *)
+ ((uintptr_t) value & (uintptr_t) ~3);
+ return hwc->value;
}
+ hwc = (ngx_hash_wildcard_t *) ((uintptr_t) value & (uintptr_t) ~3);
+
value = ngx_hash_find_wc_head(hwc, name, n - 1);
if (value) {
@@ -121,6 +123,18 @@ ngx_hash_find_wc_head(ngx_hash_wildcard_t *hwc, u_char *name, size_t len)
return hwc->value;
}
+ if ((uintptr_t) value & 1) {
+
+ if (n == 0) {
+
+ /* "example.com" */
+
+ return NULL;
+ }
+
+ return (void *) ((uintptr_t) value & (uintptr_t) ~3);
+ }
+
return value;
}
@@ -135,11 +149,7 @@ ngx_hash_find_wc_tail(ngx_hash_wildcard_t *hwc, u_char *name, size_t len)
ngx_uint_t i, key;
#if 0
- ngx_str_t line;
-
- line.len = len;
- line.data = name;
- ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "wct:\"%V\"", &line);
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "wct:\"%*s\"", len, name);
#endif
key = 0;
@@ -162,15 +172,19 @@ ngx_hash_find_wc_tail(ngx_hash_wildcard_t *hwc, u_char *name, size_t len)
value = ngx_hash_find(&hwc->hash, key, name, i);
+#if 0
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "value:\"%p\"", value);
+#endif
+
if (value) {
/*
* the 2 low bits of value have the special meaning:
- * 00 - value is data pointer,
- * 01 - value is pointer to wildcard hash allowing "example.*".
+ * 00 - value is data pointer;
+ * 11 - value is pointer to wildcard hash allowing "example.*".
*/
- if ((uintptr_t) value & 1) {
+ if ((uintptr_t) value & 2) {
i++;
@@ -569,13 +583,12 @@ ngx_hash_wildcard_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names,
if (names[n].key.len == len) {
wdc->value = names[n].value;
-#if 0
- ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0,
- "wdc: \"%V\"", wdc->value);
-#endif
}
- name->value = (void *) ((uintptr_t) wdc | (dot ? 1 : 3));
+ name->value = (void *) ((uintptr_t) wdc | (dot ? 3 : 1));
+
+ } else if (dot) {
+ name->value = (void *) ((uintptr_t) name->value | 1);
}
}
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index c1798b5bc..99b25813b 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -291,3 +291,42 @@ ngx_gmtime(time_t t, ngx_tm_t *tp)
tp->ngx_tm_year = (ngx_tm_year_t) year;
tp->ngx_tm_wday = (ngx_tm_wday_t) wday;
}
+
+
+time_t
+ngx_next_time(time_t when)
+{
+ time_t now, next;
+ struct tm tm;
+
+ now = ngx_time();
+
+ ngx_libc_localtime(now, &tm);
+
+ tm.tm_hour = (int) (when / 3600);
+ when %= 3600;
+ tm.tm_min = (int) (when / 60);
+ tm.tm_sec = (int) (when % 60);
+
+ next = mktime(&tm);
+
+ if (next == -1) {
+ return -1;
+ }
+
+ if (next - now > 0) {
+ return next;
+ }
+
+ tm.tm_mday++;
+
+ /* mktime() should normalize a date (Jan 32, etc) */
+
+ next = mktime(&tm);
+
+ if (next != -1) {
+ return next;
+ }
+
+ return -1;
+}
diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h
index 6e7ab638c..8363ca136 100644
--- a/src/core/ngx_times.h
+++ b/src/core/ngx_times.h
@@ -25,6 +25,9 @@ u_char *ngx_http_time(u_char *buf, time_t t);
u_char *ngx_http_cookie_time(u_char *buf, time_t t);
void ngx_gmtime(time_t t, ngx_tm_t *tp);
+time_t ngx_next_time(time_t when);
+#define ngx_next_time_n "mktime()"
+
extern volatile ngx_time_t *ngx_cached_time;
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index 40e371280..af54b5050 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -505,9 +505,6 @@ ngx_ssl_handshake(ngx_connection_t *c)
if (n == 1) {
- c->read->ready = 0;
- c->write->ready = 1;
-
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_addition_filter_module.c b/src/http/modules/ngx_http_addition_filter_module.c
index 948008212..55b1ca8e0 100644
--- a/src/http/modules/ngx_http_addition_filter_module.c
+++ b/src/http/modules/ngx_http_addition_filter_module.c
@@ -10,13 +10,16 @@
typedef struct {
- ngx_str_t before_body;
- ngx_str_t after_body;
+ ngx_str_t before_body;
+ ngx_str_t after_body;
+
+ ngx_hash_t types;
+ ngx_array_t *types_keys;
} ngx_http_addition_conf_t;
typedef struct {
- ngx_uint_t before_body_sent;
+ ngx_uint_t before_body_sent;
} ngx_http_addition_ctx_t;
@@ -42,6 +45,13 @@ static ngx_command_t ngx_http_addition_commands[] = {
offsetof(ngx_http_addition_conf_t, after_body),
NULL },
+ { ngx_string("addtion_types"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
+ ngx_http_types_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_addition_conf_t, types_keys),
+ &ngx_http_html_default_types[0] },
+
ngx_null_command
};
@@ -87,10 +97,7 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
ngx_http_addition_ctx_t *ctx;
ngx_http_addition_conf_t *conf;
- if (r->headers_out.status != NGX_HTTP_OK
- || r != r->main
- || r->headers_out.content_type.data == NULL)
- {
+ if (r->headers_out.status != NGX_HTTP_OK || r != r->main) {
return ngx_http_next_header_filter(r);
}
@@ -100,10 +107,7 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- if (ngx_strncasecmp(r->headers_out.content_type.data,
- (u_char *) "text/html", sizeof("text/html") - 1)
- != 0)
- {
+ if (ngx_http_test_content_type(r, &conf->types) == NULL) {
return ngx_http_next_header_filter(r);
}
@@ -214,10 +218,10 @@ ngx_http_addition_create_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * conf->before_body.len = 0;
- * conf->before_body.date = NULL;
- * conf->after_body.len = 0;
- * conf->after_body.date = NULL;
+ * conf->before_body = { 0, NULL };
+ * conf->after_body = { 0, NULL };
+ * conf->types = { NULL };
+ * conf->types_keys = NULL;
*/
return conf;
@@ -233,5 +237,13 @@ ngx_http_addition_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_html_default_types)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c
index 8ca859bd2..459143a46 100644
--- a/src/http/modules/ngx_http_charset_filter_module.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -52,6 +52,9 @@ typedef struct {
ngx_int_t charset;
ngx_int_t source_charset;
ngx_flag_t override_charset;
+
+ ngx_hash_t types;
+ ngx_array_t *types_keys;
} ngx_http_charset_loc_conf_t;
@@ -110,6 +113,18 @@ static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
static ngx_int_t ngx_http_charset_postconfiguration(ngx_conf_t *cf);
+ngx_str_t ngx_http_charset_default_types[] = {
+ ngx_string("text/html"),
+ ngx_string("text/css"),
+ ngx_string("text/xml"),
+ ngx_string("text/plain"),
+ ngx_string("text/vnd.wap.wml"),
+ ngx_string("application/x-javascript"),
+ ngx_string("application/rss+xml"),
+ ngx_null_string
+};
+
+
static ngx_command_t ngx_http_charset_filter_commands[] = {
{ ngx_string("charset"),
@@ -136,6 +151,13 @@ static ngx_command_t ngx_http_charset_filter_commands[] = {
offsetof(ngx_http_charset_loc_conf_t, override_charset),
NULL },
+ { ngx_string("charset_types"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
+ ngx_http_types_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_charset_loc_conf_t, types_keys),
+ &ngx_http_charset_default_types[0] },
+
{ ngx_string("charset_map"),
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
ngx_http_charset_map_block,
@@ -185,7 +207,6 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t
ngx_http_charset_header_filter(ngx_http_request_t *r)
{
- u_char *ct;
ngx_int_t charset, source_charset;
ngx_str_t *mc, *from, *to, s;
ngx_uint_t n;
@@ -243,13 +264,7 @@ ngx_http_charset_header_filter(ngx_http_request_t *r)
}
} else {
- ct = r->headers_out.content_type.data;
-
- if (ngx_strncasecmp(ct, (u_char *) "text/", 5) != 0
- && ngx_strncasecmp(ct,
- (u_char *) "application/x-javascript", 24)
- != 0)
- {
+ if (ngx_http_test_content_type(r, &mlcf->types) == NULL) {
return ngx_http_next_header_filter(r);
}
}
@@ -1444,6 +1459,13 @@ ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
return NGX_CONF_ERROR;
}
+ /*
+ * set by ngx_pcalloc():
+ *
+ * lcf->types = { NULL };
+ * lcf->types_keys = NULL;
+ */
+
lcf->charset = NGX_CONF_UNSET;
lcf->source_charset = NGX_CONF_UNSET;
lcf->override_charset = NGX_CONF_UNSET;
@@ -1501,6 +1523,14 @@ ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
recode->src = conf->source_charset;
recode->dst = conf->charset;
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_charset_default_types)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index 1ff45ea76..8c307aec1 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -15,7 +15,7 @@ typedef struct {
ngx_flag_t enable;
ngx_flag_t no_buffer;
- ngx_array_t *types; /* array of ngx_str_t */
+ ngx_hash_t types;
ngx_bufs_t bufs;
@@ -23,6 +23,8 @@ typedef struct {
size_t wbits;
size_t memlevel;
ssize_t min_length;
+
+ ngx_array_t *types_keys;
} ngx_http_gzip_conf_t;
@@ -68,8 +70,6 @@ static ngx_int_t ngx_http_gzip_filter_init(ngx_conf_t *cf);
static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
void *parent, void *child);
-static char *ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data);
static char *ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data);
@@ -101,10 +101,10 @@ static ngx_command_t ngx_http_gzip_filter_commands[] = {
{ ngx_string("gzip_types"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
- ngx_http_gzip_types,
+ ngx_http_types_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- 0,
- NULL },
+ offsetof(ngx_http_gzip_conf_t, types_keys),
+ &ngx_http_html_default_types[0] },
{ ngx_string("gzip_comp_level"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
@@ -204,8 +204,6 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t
ngx_http_gzip_header_filter(ngx_http_request_t *r)
{
- ngx_str_t *type;
- ngx_uint_t i;
ngx_table_elt_t *h;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
@@ -217,30 +215,16 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
&& r->headers_out.status != NGX_HTTP_FORBIDDEN
&& r->headers_out.status != NGX_HTTP_NOT_FOUND)
|| r->header_only
- || r->headers_out.content_type.len == 0
|| (r->headers_out.content_encoding
&& r->headers_out.content_encoding->value.len)
|| (r->headers_out.content_length_n != -1
&& r->headers_out.content_length_n < conf->min_length)
+ || ngx_http_test_content_type(r, &conf->types) == NULL
|| ngx_http_gzip_ok(r) != NGX_OK)
{
return ngx_http_next_header_filter(r);
}
- type = conf->types->elts;
- for (i = 0; i < conf->types->nelts; i++) {
- if (r->headers_out.content_type.len >= type[i].len
- && ngx_strncasecmp(r->headers_out.content_type.data,
- type[i].data, type[i].len) == 0)
- {
- goto found;
- }
- }
-
- return ngx_http_next_header_filter(r);
-
-found:
-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
@@ -826,7 +810,8 @@ ngx_http_gzip_create_conf(ngx_conf_t *cf)
* set by ngx_pcalloc():
*
* conf->bufs.num = 0;
- * conf->types = NULL;
+ * conf->types = { NULL };
+ * conf->types_keys = NULL;
*/
conf->enable = NGX_CONF_UNSET;
@@ -847,8 +832,6 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_gzip_conf_t *prev = parent;
ngx_http_gzip_conf_t *conf = child;
- ngx_str_t *type;
-
ngx_conf_merge_value(conf->enable, prev->enable, 0);
ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize);
@@ -860,24 +843,12 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
- if (conf->types == NULL) {
- if (prev->types == NULL) {
- conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
- if (conf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(conf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
-
- } else {
- conf->types = prev->types;
- }
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_html_default_types)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
}
return NGX_CONF_OK;
@@ -898,56 +869,6 @@ ngx_http_gzip_filter_init(ngx_conf_t *cf)
static char *
-ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_gzip_conf_t *gcf = conf;
-
- ngx_str_t *value, *type;
- ngx_uint_t i;
-
- if (gcf->types == NULL) {
- gcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
- if (gcf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(gcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
- }
-
- value = cf->args->elts;
-
- for (i = 1; i < cf->args->nelts; i++) {
-
- if (ngx_strcmp(value[i].data, "text/html") == 0) {
- continue;
- }
-
- type = ngx_array_push(gcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = value[i].len;
-
- type->data = ngx_pnalloc(cf->pool, type->len + 1);
- if (type->data == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_cpystrn(type->data, value[i].data, type->len + 1);
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data)
{
int *np = data;
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
index 95d846ffb..f4a6fe76f 100644
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -36,6 +36,7 @@ struct ngx_http_header_val_s {
#define NGX_HTTP_EXPIRES_MAX 2
#define NGX_HTTP_EXPIRES_ACCESS 3
#define NGX_HTTP_EXPIRES_MODIFIED 4
+#define NGX_HTTP_EXPIRES_DAILY 5
typedef struct {
@@ -187,7 +188,7 @@ static ngx_int_t
ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
{
size_t len;
- time_t since;
+ time_t now, expires_time, max_age;
ngx_uint_t i;
ngx_table_elt_t *expires, *cc, **ccp;
@@ -279,16 +280,24 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
return NGX_OK;
}
+ now = ngx_time();
+
if (conf->expires == NGX_HTTP_EXPIRES_ACCESS
|| r->headers_out.last_modified_time == -1)
{
- since = ngx_time();
+ expires_time = now + conf->expires_time;
+ max_age = conf->expires_time;
+
+ } else if (conf->expires == NGX_HTTP_EXPIRES_DAILY) {
+ expires_time = ngx_next_time(conf->expires_time);
+ max_age = expires_time - now;
} else {
- since = r->headers_out.last_modified_time;
+ expires_time = r->headers_out.last_modified_time + conf->expires_time;
+ max_age = expires_time - now;
}
- ngx_http_time(expires->value.data, since + conf->expires_time);
+ ngx_http_time(expires->value.data, expires_time);
if (conf->expires_time < 0) {
cc->value.len = sizeof("no-cache") - 1;
@@ -303,8 +312,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
return NGX_ERROR;
}
- cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T",
- since + conf->expires_time - ngx_time())
+ cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", max_age)
- cc->value.data;
return NGX_OK;
@@ -514,7 +522,18 @@ ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
n = 2;
}
- if (value[n].data[0] == '+') {
+ if (value[n].data[0] == '@') {
+ value[n].data++;
+ value[n].len--;
+ minus = 0;
+
+ if (hcf->expires == NGX_HTTP_EXPIRES_MODIFIED) {
+ return "daily time can not be used with \"modified\" parameter";
+ }
+
+ hcf->expires = NGX_HTTP_EXPIRES_DAILY;
+
+ } else if (value[n].data[0] == '+') {
value[n].data++;
value[n].len--;
minus = 0;
@@ -534,6 +553,12 @@ ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "invalid value";
}
+ if (hcf->expires == NGX_HTTP_EXPIRES_DAILY
+ && hcf->expires_time > 24 * 60 * 60)
+ {
+ return "daily time value must be less than 24 hours";
+ }
+
if (hcf->expires_time == NGX_PARSE_LARGE_TIME) {
return "value must be less than 68 years";
}
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
index 6d4cf34d3..a03b9f62e 100644
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -27,8 +27,8 @@ typedef struct {
static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
ngx_http_core_loc_conf_t *clcf, u_char *path, u_char *last);
-static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, u_char *file,
- ngx_err_t err);
+static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
+ ngx_http_core_loc_conf_t *clcf, u_char *file, ngx_err_t err);
static ngx_int_t ngx_http_index_init(ngx_conf_t *cf);
static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf);
@@ -227,7 +227,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
}
if (of.err == NGX_ENOTDIR || of.err == NGX_EACCES) {
- return ngx_http_index_error(r, path.data, of.err);
+ return ngx_http_index_error(r, clcf, path.data, of.err);
}
if (!dir_tested) {
@@ -306,7 +306,7 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
if (of.err == NGX_ENOENT) {
*last = c;
- return ngx_http_index_error(r, dir.data, NGX_ENOENT);
+ return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT);
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
@@ -330,7 +330,8 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
static ngx_int_t
-ngx_http_index_error(ngx_http_request_t *r, u_char *file, ngx_err_t err)
+ngx_http_index_error(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
+ u_char *file, ngx_err_t err)
{
if (err == NGX_EACCES) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
@@ -339,8 +340,10 @@ ngx_http_index_error(ngx_http_request_t *r, u_char *file, ngx_err_t err)
return NGX_HTTP_FORBIDDEN;
}
- ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
- "\"%s\" is not found", file);
+ if (clcf->log_not_found) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
+ "\"%s\" is not found", file);
+ }
return NGX_HTTP_NOT_FOUND;
}
diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c
index 5de41f325..04ab04200 100644
--- a/src/http/modules/ngx_http_ssi_filter_module.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -22,10 +22,12 @@ typedef struct {
ngx_flag_t silent_errors;
ngx_flag_t ignore_recycled_buffers;
- ngx_array_t *types; /* array of ngx_str_t */
+ ngx_hash_t types;
size_t min_file_chunk;
size_t value_len;
+
+ ngx_array_t *types_keys;
} ngx_http_ssi_loc_conf_t;
@@ -102,8 +104,6 @@ static ngx_int_t ngx_http_ssi_endblock(ngx_http_request_t *r,
static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t gmt);
-static char *ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-
static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf);
static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf);
@@ -153,10 +153,10 @@ static ngx_command_t ngx_http_ssi_filter_commands[] = {
{ ngx_string("ssi_types"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
- ngx_http_ssi_types,
+ ngx_http_types_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- 0,
- NULL },
+ offsetof(ngx_http_ssi_loc_conf_t, types_keys),
+ &ngx_http_html_default_types[0] },
ngx_null_command
};
@@ -316,36 +316,18 @@ static ngx_http_variable_t ngx_http_ssi_vars[] = {
static ngx_int_t
ngx_http_ssi_header_filter(ngx_http_request_t *r)
{
- ngx_uint_t i;
- ngx_str_t *type;
ngx_http_ssi_ctx_t *ctx;
ngx_http_ssi_loc_conf_t *slcf;
slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
if (!slcf->enable
- || r->headers_out.content_type.len == 0
- || r->headers_out.content_length_n == 0)
+ || r->headers_out.content_length_n == 0
+ || ngx_http_test_content_type(r, &slcf->types) == NULL)
{
return ngx_http_next_header_filter(r);
}
-
- type = slcf->types->elts;
- for (i = 0; i < slcf->types->nelts; i++) {
- if (r->headers_out.content_type.len >= type[i].len
- && ngx_strncasecmp(r->headers_out.content_type.data,
- type[i].data, type[i].len) == 0)
- {
- goto found;
- }
- }
-
- return ngx_http_next_header_filter(r);
-
-
-found:
-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
@@ -2679,56 +2661,6 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
}
-static char *
-ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_ssi_loc_conf_t *slcf = conf;
-
- ngx_str_t *value, *type;
- ngx_uint_t i;
-
- if (slcf->types == NULL) {
- slcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
- if (slcf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(slcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
- }
-
- value = cf->args->elts;
-
- for (i = 1; i < cf->args->nelts; i++) {
-
- if (ngx_strcmp(value[i].data, "text/html") == 0) {
- continue;
- }
-
- type = ngx_array_push(slcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = value[i].len;
-
- type->data = ngx_pnalloc(cf->pool, type->len + 1);
- if (type->data == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_cpystrn(type->data, value[i].data, type->len + 1);
- }
-
- return NGX_CONF_OK;
-}
-
-
static ngx_int_t
ngx_http_ssi_preconfiguration(ngx_conf_t *cf)
{
@@ -2829,7 +2761,8 @@ ngx_http_ssi_create_loc_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * conf->types = NULL;
+ * conf->types = { NULL };
+ * conf->types_keys = NULL;
*/
slcf->enable = NGX_CONF_UNSET;
@@ -2849,8 +2782,6 @@ ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_ssi_loc_conf_t *prev = parent;
ngx_http_ssi_loc_conf_t *conf = child;
- ngx_str_t *type;
-
ngx_conf_merge_value(conf->enable, prev->enable, 0);
ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0);
ngx_conf_merge_value(conf->ignore_recycled_buffers,
@@ -2859,24 +2790,12 @@ ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024);
ngx_conf_merge_size_value(conf->value_len, prev->value_len, 256);
- if (conf->types == NULL) {
- if (prev->types == NULL) {
- conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
- if (conf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(conf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
-
- } else {
- conf->types = prev->types;
- }
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_html_default_types)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
}
return NGX_CONF_OK;
diff --git a/src/http/modules/ngx_http_sub_filter_module.c b/src/http/modules/ngx_http_sub_filter_module.c
index 62a8f0814..f40a3c654 100644
--- a/src/http/modules/ngx_http_sub_filter_module.c
+++ b/src/http/modules/ngx_http_sub_filter_module.c
@@ -13,12 +13,14 @@ typedef struct {
ngx_str_t match;
ngx_str_t sub;
- ngx_array_t *types; /* array of ngx_str_t */
+ ngx_hash_t types;
ngx_array_t *sub_lengths;
ngx_array_t *sub_values;
ngx_flag_t once;
+
+ ngx_array_t *types_keys;
} ngx_http_sub_loc_conf_t;
@@ -60,7 +62,6 @@ static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
-static char *ngx_http_sub_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static void *ngx_http_sub_create_conf(ngx_conf_t *cf);
static char *ngx_http_sub_merge_conf(ngx_conf_t *cf,
void *parent, void *child);
@@ -78,10 +79,10 @@ static ngx_command_t ngx_http_sub_filter_commands[] = {
{ ngx_string("sub_filter_types"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
- ngx_http_sub_types,
+ ngx_http_types_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- 0,
- NULL },
+ offsetof(ngx_http_sub_loc_conf_t, types_keys),
+ &ngx_http_html_default_types[0] },
{ ngx_string("sub_filter_once"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
@@ -132,34 +133,18 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t
ngx_http_sub_header_filter(ngx_http_request_t *r)
{
- ngx_str_t *type;
- ngx_uint_t i;
ngx_http_sub_ctx_t *ctx;
ngx_http_sub_loc_conf_t *slcf;
slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
if (slcf->match.len == 0
- || r->headers_out.content_type.len == 0
- || r->headers_out.content_length_n == 0)
+ || r->headers_out.content_length_n == 0
+ || ngx_http_test_content_type(r, &slcf->types) == NULL)
{
return ngx_http_next_header_filter(r);
}
- type = slcf->types->elts;
- for (i = 0; i < slcf->types->nelts; i++) {
- if (r->headers_out.content_type.len >= type[i].len
- && ngx_strncasecmp(r->headers_out.content_type.data,
- type[i].data, type[i].len) == 0)
- {
- goto found;
- }
- }
-
- return ngx_http_next_header_filter(r);
-
-found:
-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_sub_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
@@ -669,56 +654,6 @@ ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static char *
-ngx_http_sub_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_sub_loc_conf_t *slcf = conf;
-
- ngx_str_t *value, *type;
- ngx_uint_t i;
-
- if (slcf->types == NULL) {
- slcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
- if (slcf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(slcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
- }
-
- value = cf->args->elts;
-
- for (i = 1; i < cf->args->nelts; i++) {
-
- if (ngx_strcmp(value[i].data, "text/html") == 0) {
- continue;
- }
-
- type = ngx_array_push(slcf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = value[i].len;
-
- type->data = ngx_pnalloc(cf->pool, type->len + 1);
- if (type->data == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_cpystrn(type->data, value[i].data, type->len + 1);
- }
-
- return NGX_CONF_OK;
-}
-
-
static void *
ngx_http_sub_create_conf(ngx_conf_t *cf)
{
@@ -732,13 +667,12 @@ ngx_http_sub_create_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * conf->match.len = 0;
- * conf->match.data = NULL;
- * conf->sub.len = 0;
- * conf->sub.data = NULL;
+ * conf->match = { 0, NULL };
+ * conf->sub = { 0, NULL };
* conf->sub_lengths = NULL;
* conf->sub_values = NULL;
- * conf->types = NULL;
+ * conf->types = { NULL };
+ * conf->types_keys = NULL;
*/
slcf->once = NGX_CONF_UNSET;
@@ -753,8 +687,6 @@ ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_sub_loc_conf_t *prev = parent;
ngx_http_sub_loc_conf_t *conf = child;
- ngx_str_t *type;
-
ngx_conf_merge_value(conf->once, prev->once, 1);
ngx_conf_merge_str_value(conf->match, prev->match, "");
@@ -764,24 +696,12 @@ ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
conf->sub_values = prev->sub_values;
}
- if (conf->types == NULL) {
- if (prev->types == NULL) {
- conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
- if (conf->types == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type = ngx_array_push(conf->types);
- if (type == NULL) {
- return NGX_CONF_ERROR;
- }
-
- type->len = sizeof("text/html") - 1;
- type->data = (u_char *) "text/html";
-
- } else {
- conf->types = prev->types;
- }
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_html_default_types)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
}
return NGX_CONF_OK;
diff --git a/src/http/modules/ngx_http_xslt_filter_module.c b/src/http/modules/ngx_http_xslt_filter_module.c
index 364fed642..5ab59d4a1 100644
--- a/src/http/modules/ngx_http_xslt_filter_module.c
+++ b/src/http/modules/ngx_http_xslt_filter_module.c
@@ -22,6 +22,18 @@
typedef struct {
+ u_char *name;
+ void *data;
+} ngx_http_xslt_file_t;
+
+
+typedef struct {
+ ngx_array_t dtd_files; /* ngx_http_xslt_file_t */
+ ngx_array_t sheet_files; /* ngx_http_xslt_file_t */
+} ngx_http_xslt_filter_main_conf_t;
+
+
+typedef struct {
ngx_array_t *lengths;
ngx_array_t *values;
} ngx_http_xslt_param_t;
@@ -35,10 +47,10 @@ typedef struct {
typedef struct {
xmlDtdPtr dtd;
- ngx_array_t sheets; /* ngx_http_xslt_sheet_t */
- ngx_hash_t types_hash;
- ngx_array_t *keys;
-} ngx_http_xslt_filter_conf_t;
+ ngx_array_t sheets; /* ngx_http_xslt_sheet_t */
+ ngx_hash_t types;
+ ngx_array_t *types_keys;
+} ngx_http_xslt_filter_loc_conf_t;
typedef struct {
@@ -47,8 +59,8 @@ typedef struct {
xmlSAXHandler *sax;
ngx_http_request_t *request;
ngx_array_t params;
- unsigned done:1;
- unsigned html:1;
+
+ ngx_uint_t done; /* unsigned done:1; */
} ngx_http_xslt_filter_ctx_t;
@@ -109,13 +121,17 @@ static ngx_buf_t *ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
ngx_http_xslt_filter_ctx_t *ctx);
static ngx_int_t ngx_http_xslt_params(ngx_http_request_t *r,
ngx_http_xslt_filter_ctx_t *ctx, ngx_array_t *params);
+static u_char *ngx_http_xslt_content_type(xsltStylesheetPtr s);
+static u_char *ngx_http_xslt_encoding(xsltStylesheetPtr s);
static void ngx_http_xslt_cleanup(void *data);
static char *ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+static void ngx_http_xslt_cleanup_dtd(void *data);
static void ngx_http_xslt_cleanup_stylesheet(void *data);
+static void *ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf);
static void *ngx_http_xslt_filter_create_conf(ngx_conf_t *cf);
static char *ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent,
void *child);
@@ -131,24 +147,24 @@ ngx_str_t ngx_http_xslt_default_types[] = {
static ngx_command_t ngx_http_xslt_filter_commands[] = {
{ ngx_string("xml_entities"),
- NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_xslt_entities,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("xslt_stylesheet"),
- NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_1MORE,
+ NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_http_xslt_stylesheet,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("xslt_types"),
- NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_1MORE,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_http_types_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_xslt_filter_conf_t, keys),
+ offsetof(ngx_http_xslt_filter_loc_conf_t, types_keys),
&ngx_http_xslt_default_types[0] },
ngx_null_command
@@ -159,7 +175,7 @@ static ngx_http_module_t ngx_http_xslt_filter_module_ctx = {
NULL, /* preconfiguration */
ngx_http_xslt_filter_init, /* postconfiguration */
- NULL, /* create main configuration */
+ ngx_http_xslt_filter_create_main_conf, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
@@ -193,8 +209,8 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t
ngx_http_xslt_header_filter(ngx_http_request_t *r)
{
- ngx_http_xslt_filter_ctx_t *ctx;
- ngx_http_xslt_filter_conf_t *conf;
+ ngx_http_xslt_filter_ctx_t *ctx;
+ ngx_http_xslt_filter_loc_conf_t *conf;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"xslt filter header");
@@ -206,7 +222,7 @@ ngx_http_xslt_header_filter(ngx_http_request_t *r)
conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
if (conf->sheets.nelts == 0
- || ngx_http_test_content_type(r, &conf->types_hash) == NULL)
+ || ngx_http_test_content_type(r, &conf->types) == NULL)
{
return ngx_http_next_header_filter(r);
}
@@ -316,21 +332,17 @@ ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
NGX_HTTP_INTERNAL_SERVER_ERROR);
}
- if (ctx->html) {
- r->headers_out.content_type_len = sizeof("text/html") - 1;
- r->headers_out.content_type.len = sizeof("text/html") - 1;
- r->headers_out.content_type.data = (u_char *) "text/html";
- }
+ if (r == r->main) {
+ r->headers_out.content_length_n = b->last - b->pos;
- r->headers_out.content_length_n = b->last - b->pos;
+ if (r->headers_out.content_length) {
+ r->headers_out.content_length->hash = 0;
+ r->headers_out.content_length = NULL;
+ }
- if (r->headers_out.content_length) {
- r->headers_out.content_length->hash = 0;
- r->headers_out.content_length = NULL;
+ ngx_http_clear_last_modified(r);
}
- r->allow_ranges = 1;
-
rc = ngx_http_next_header_filter(r);
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
@@ -481,10 +493,10 @@ ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
{
ngx_http_xslt_filter_ctx_t *ctx = data;
- xmlDocPtr doc;
- xmlDtdPtr dtd;
- ngx_http_request_t *r;
- ngx_http_xslt_filter_conf_t *conf;
+ xmlDocPtr doc;
+ xmlDtdPtr dtd;
+ ngx_http_request_t *r;
+ ngx_http_xslt_filter_loc_conf_t *conf;
r = ctx->request;
@@ -511,8 +523,6 @@ ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
return;
}
- dtd->name = xmlStrdup(name);
-
if (doc->children == NULL) {
xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
@@ -732,13 +742,14 @@ static ngx_buf_t *
ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
ngx_http_xslt_filter_ctx_t *ctx)
{
- int len, rc;
- ngx_buf_t *b;
- ngx_uint_t i;
- xmlChar *buf;
- xmlDocPtr doc, res;
- ngx_http_xslt_sheet_t *sheet;
- ngx_http_xslt_filter_conf_t *conf;
+ int len, rc, doc_type;
+ u_char *type, *encoding;
+ ngx_buf_t *b;
+ ngx_uint_t i;
+ xmlChar *buf;
+ xmlDocPtr doc, res;
+ ngx_http_xslt_sheet_t *sheet;
+ ngx_http_xslt_filter_loc_conf_t *conf;
conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
sheet = conf->sheets.elts;
@@ -776,10 +787,22 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
ctx->params.nelts = 0;
}
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "xslt filter doc type: %d", doc->type);
+ /* there must be at least one stylesheet */
- ctx->html = (doc->type == XML_HTML_DOCUMENT_NODE) ? 1 : 0;
+ if (r == r->main) {
+ type = ngx_http_xslt_content_type(sheet[i - 1].stylesheet);
+
+ } else {
+ type = NULL;
+ }
+
+ encoding = ngx_http_xslt_encoding(sheet[i - 1].stylesheet);
+ doc_type = doc->type;
+
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "xslt filter type: %d t:%s e:%s",
+ doc_type, type ? type : (u_char *) "(null)",
+ encoding ? encoding : (u_char *) "(null)");
rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet);
@@ -808,6 +831,29 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
b->memory = 1;
b->last_buf = 1;
+ if (encoding) {
+ r->headers_out.charset.len = ngx_strlen(encoding);
+ r->headers_out.charset.data = encoding;
+ }
+
+ if (r != r->main) {
+ return b;
+ }
+
+ if (type) {
+ len = ngx_strlen(type);
+
+ r->headers_out.content_type_len = len;
+ r->headers_out.content_type.len = len;
+ r->headers_out.content_type.data = type;
+
+ } else if (doc_type == XML_HTML_DOCUMENT_NODE) {
+
+ r->headers_out.content_type_len = sizeof("text/html") - 1;
+ r->headers_out.content_type.len = sizeof("text/html") - 1;
+ r->headers_out.content_type.data = (u_char *) "text/html";
+ }
+
return b;
}
@@ -906,6 +952,50 @@ ngx_http_xslt_params(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
}
+static u_char *
+ngx_http_xslt_content_type(xsltStylesheetPtr s)
+{
+ u_char *type;
+
+ if (s->mediaType) {
+ return s->mediaType;
+ }
+
+ for (s = s->imports; s; s = s->next) {
+
+ type = ngx_http_xslt_content_type(s);
+
+ if (type) {
+ return type;
+ }
+ }
+
+ return NULL;
+}
+
+
+static u_char *
+ngx_http_xslt_encoding(xsltStylesheetPtr s)
+{
+ u_char *encoding;
+
+ if (s->encoding) {
+ return s->encoding;
+ }
+
+ for (s = s->imports; s; s = s->next) {
+
+ encoding = ngx_http_xslt_encoding(s);
+
+ if (encoding) {
+ return encoding;
+ }
+ }
+
+ return NULL;
+}
+
+
static void
ngx_http_xslt_cleanup(void *data)
{
@@ -916,9 +1006,13 @@ ngx_http_xslt_cleanup(void *data)
static char *
ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- ngx_http_xslt_filter_conf_t *xlcf = conf;
+ ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
- ngx_str_t *value;
+ ngx_str_t *value;
+ ngx_uint_t i;
+ ngx_pool_cleanup_t *cln;
+ ngx_http_xslt_file_t *file;
+ ngx_http_xslt_filter_main_conf_t *xmcf;
if (xlcf->dtd) {
return "is duplicate";
@@ -926,6 +1020,21 @@ ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts;
+ xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module);
+
+ file = xmcf->dtd_files.elts;
+ for (i = 0; i < xmcf->dtd_files.nelts; i++) {
+ if (ngx_strcmp(file[i].name, &value[1].data) == 0) {
+ xlcf->dtd = file[i].data;
+ return NGX_CONF_OK;
+ }
+ }
+
+ cln = ngx_pool_cleanup_add(cf->pool, 0);
+ if (cln == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
xlcf->dtd = xmlParseDTD(NULL, (xmlChar *) value[1].data);
if (xlcf->dtd == NULL) {
@@ -933,6 +1042,17 @@ ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
+ cln->handler = ngx_http_xslt_cleanup_dtd;
+ cln->data = xlcf->dtd;
+
+ file = ngx_array_push(&xmcf->dtd_files);
+ if (file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ file->name = value[1].data;
+ file->data = xlcf->dtd;
+
return NGX_CONF_OK;
}
@@ -941,14 +1061,16 @@ ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- ngx_http_xslt_filter_conf_t *xlcf = conf;
+ ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
- ngx_str_t *value;
- ngx_uint_t i, n;
- ngx_pool_cleanup_t *cln;
- ngx_http_xslt_sheet_t *sheet;
- ngx_http_xslt_param_t *param;
- ngx_http_script_compile_t sc;
+ ngx_str_t *value;
+ ngx_uint_t i, n;
+ ngx_pool_cleanup_t *cln;
+ ngx_http_xslt_file_t *file;
+ ngx_http_xslt_sheet_t *sheet;
+ ngx_http_xslt_param_t *param;
+ ngx_http_script_compile_t sc;
+ ngx_http_xslt_filter_main_conf_t *xmcf;
value = cf->args->elts;
@@ -972,6 +1094,16 @@ ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
+ xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module);
+
+ file = xmcf->sheet_files.elts;
+ for (i = 0; i < xmcf->sheet_files.nelts; i++) {
+ if (ngx_strcmp(file[i].name, &value[1].data) == 0) {
+ sheet->stylesheet = file[i].data;
+ goto found;
+ }
+ }
+
cln = ngx_pool_cleanup_add(cf->pool, 0);
if (cln == NULL) {
return NGX_CONF_ERROR;
@@ -988,6 +1120,16 @@ ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
cln->handler = ngx_http_xslt_cleanup_stylesheet;
cln->data = sheet->stylesheet;
+ file = ngx_array_push(&xmcf->sheet_files);
+ if (file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ file->name = value[1].data;
+ file->data = sheet->stylesheet;
+
+found:
+
n = cf->args->nelts;
if (n == 2) {
@@ -1031,21 +1173,53 @@ ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static void
-ngx_http_xslt_cleanup_stylesheet(void *data)
+ngx_http_xslt_cleanup_dtd(void *data)
{
- xsltStylesheetPtr stylesheet = data;
+ xmlFreeDtd(data);
+}
- xsltFreeStylesheet(stylesheet);
+
+static void
+ngx_http_xslt_cleanup_stylesheet(void *data)
+{
+ xsltFreeStylesheet(data);
}
+static void *
+ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf)
+{
+ ngx_http_xslt_filter_main_conf_t *conf;
+
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_xslt_filter_main_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_array_init(&conf->dtd_files, cf->pool, 1,
+ sizeof(ngx_http_xslt_file_t))
+ != NGX_OK)
+ {
+ return NULL;
+ }
+
+ if (ngx_array_init(&conf->sheet_files, cf->pool, 1,
+ sizeof(ngx_http_xslt_file_t))
+ != NGX_OK)
+ {
+ return NULL;
+ }
+
+ return conf;
+}
+
static void *
ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
{
- ngx_http_xslt_filter_conf_t *conf;
+ ngx_http_xslt_filter_loc_conf_t *conf;
- conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_xslt_filter_conf_t));
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_xslt_filter_loc_conf_t));
if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1053,8 +1227,10 @@ ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * conf->dtd
- * conf->sheets
+ * conf->dtd = NULL;
+ * conf->sheets = { NULL };
+ * conf->types = { NULL };
+ * conf->types_keys = NULL;
*/
return conf;
@@ -1064,8 +1240,8 @@ ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
static char *
ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
- ngx_http_xslt_filter_conf_t *prev = parent;
- ngx_http_xslt_filter_conf_t *conf = child;
+ ngx_http_xslt_filter_loc_conf_t *prev = parent;
+ ngx_http_xslt_filter_loc_conf_t *conf = child;
if (conf->dtd == NULL) {
conf->dtd = prev->dtd;
@@ -1075,8 +1251,9 @@ ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
conf->sheets = prev->sheets;
}
- if (ngx_http_merge_types(cf, conf->keys, &conf->types_hash, prev->keys,
- &prev->types_hash, ngx_http_xslt_default_types)
+ if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+ prev->types_keys, &prev->types,
+ ngx_http_xslt_default_types)
!= NGX_OK)
{
return NGX_CONF_ERROR;
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index f82a32810..22921d55a 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -47,7 +47,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
-our $VERSION = '0.7.8';
+our $VERSION = '0.7.9';
require XSLoader;
XSLoader::load('nginx', $VERSION);
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 1a5db19bf..024170f45 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -59,6 +59,12 @@ ngx_int_t (*ngx_http_top_header_filter) (ngx_http_request_t *r);
ngx_int_t (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
+ngx_str_t ngx_http_html_default_types[] = {
+ ngx_string("text/html"),
+ ngx_null_string
+};
+
+
static ngx_command_t ngx_http_commands[] = {
{ ngx_string("http"),
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 180da8194..afbc69de9 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -117,6 +117,8 @@ char *ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types,
extern ngx_module_t ngx_http_module;
+extern ngx_str_t ngx_http_html_default_types[];
+
extern ngx_http_output_header_filter_pt ngx_http_top_header_filter;
extern ngx_http_output_body_filter_pt ngx_http_top_body_filter;
diff --git a/src/mail/ngx_mail_handler.c b/src/mail/ngx_mail_handler.c
index 2dc5d7a31..4cc5e3e62 100644
--- a/src/mail/ngx_mail_handler.c
+++ b/src/mail/ngx_mail_handler.c
@@ -198,6 +198,8 @@ ngx_mail_ssl_handshake_handler(ngx_connection_t *c)
return;
}
+ c->read->ready = 0;
+
ngx_mail_init_session(c);
return;
}
diff --git a/src/misc/ngx_cpp_test_module.cpp b/src/misc/ngx_cpp_test_module.cpp
new file mode 100644
index 000000000..8f87dcdad
--- /dev/null
+++ b/src/misc/ngx_cpp_test_module.cpp
@@ -0,0 +1,27 @@
+
+// stub module to test header files' C++ compatibilty
+
+extern "C" {
+ #include <ngx_config.h>
+ #include <ngx_core.h>
+ #include <ngx_event.h>
+ #include <ngx_event_connect.h>
+ #include <ngx_event_pipe.h>
+
+ #include <ngx_http.h>
+
+ #include <ngx_mail.h>
+ #include <ngx_mail_pop3_module.h>
+ #include <ngx_mail_imap_module.h>
+ #include <ngx_mail_smtp_module.h>
+}
+
+// nginx header files should go before other, because they define 64-bit off_t
+// #include <string>
+
+
+void
+ngx_cpp_test_handler(void *data)
+{
+ return;
+}