summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorNGINX team <nginx@nginx.org>2012-09-12 11:05:53 +0000
committerJon Kolb <jon@b0g.us>2012-09-12 11:05:53 +0000
commitb4d1d3eec8e8bf9edf4feb5e3caf49fffffb5267 (patch)
tree0fa666325c9ee73c156f079fd9615f37edafabd8 /src/http
parent36abb5aeb0daa0ff0d466378025584765b73e047 (diff)
downloadnginx-b4d1d3eec8e8bf9edf4feb5e3caf49fffffb5267.tar.gz
Changes with nginx 1.3.6 12 Sep 2012v1.3.6
*) Feature: the ngx_http_gunzip_filter_module. *) Feature: the "memcached_gzip_flag" directive. *) Feature: the "always" parameter of the "gzip_static" directive. *) Bugfix: in the "limit_req" directive; the bug had appeared in 1.1.14. Thanks to Charles Chen. *) Bugfix: nginx could not be built by gcc 4.7 with -O2 optimization if the --with-ipv6 option was used.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_geo_module.c11
-rw-r--r--src/http/modules/ngx_http_geoip_module.c11
-rw-r--r--src/http/modules/ngx_http_gunzip_filter_module.c676
-rw-r--r--src/http/modules/ngx_http_gzip_static_module.c42
-rw-r--r--src/http/modules/ngx_http_limit_req_module.c8
-rw-r--r--src/http/modules/ngx_http_map_module.c12
-rw-r--r--src/http/modules/ngx_http_memcached_module.c64
-rw-r--r--src/http/modules/perl/nginx.pm2
-rw-r--r--src/http/ngx_http_core_module.c21
-rw-r--r--src/http/ngx_http_write_filter_module.c18
10 files changed, 809 insertions, 56 deletions
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index 230816247..fce87a8cb 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -233,12 +233,21 @@ ngx_http_geo_addr(ngx_http_request_t *r, ngx_http_geo_ctx_t *ctx)
#if (NGX_HAVE_INET6)
if (addr.sockaddr->sa_family == AF_INET6) {
+ u_char *p;
+ in_addr_t inaddr;
struct in6_addr *inaddr6;
inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
- return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
+ p = inaddr6->s6_addr;
+
+ inaddr = p[12] << 24;
+ inaddr += p[13] << 16;
+ inaddr += p[14] << 8;
+ inaddr += p[15];
+
+ return inaddr;
}
}
diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
index 0ce3bf1e5..7ff4f10fb 100644
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -226,12 +226,21 @@ ngx_http_geoip_addr(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
#if (NGX_HAVE_INET6)
if (addr.sockaddr->sa_family == AF_INET6) {
+ u_char *p;
+ in_addr_t inaddr;
struct in6_addr *inaddr6;
inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
- return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
+ p = inaddr6->s6_addr;
+
+ inaddr = p[12] << 24;
+ inaddr += p[13] << 16;
+ inaddr += p[14] << 8;
+ inaddr += p[15];
+
+ return inaddr;
}
}
diff --git a/src/http/modules/ngx_http_gunzip_filter_module.c b/src/http/modules/ngx_http_gunzip_filter_module.c
new file mode 100644
index 000000000..f8434cb83
--- /dev/null
+++ b/src/http/modules/ngx_http_gunzip_filter_module.c
@@ -0,0 +1,676 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+#include <zlib.h>
+
+
+typedef struct {
+ ngx_flag_t enable;
+ ngx_bufs_t bufs;
+} ngx_http_gunzip_conf_t;
+
+
+typedef struct {
+ ngx_chain_t *in;
+ ngx_chain_t *free;
+ ngx_chain_t *busy;
+ ngx_chain_t *out;
+ ngx_chain_t **last_out;
+
+ ngx_buf_t *in_buf;
+ ngx_buf_t *out_buf;
+ ngx_int_t bufs;
+
+ unsigned started:1;
+ unsigned flush:4;
+ unsigned redo:1;
+ unsigned done:1;
+ unsigned nomem:1;
+
+ z_stream zstream;
+ ngx_http_request_t *request;
+} ngx_http_gunzip_ctx_t;
+
+
+static ngx_int_t ngx_http_gunzip_filter_inflate_start(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx);
+static ngx_int_t ngx_http_gunzip_filter_add_data(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx);
+static ngx_int_t ngx_http_gunzip_filter_get_buf(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx);
+static ngx_int_t ngx_http_gunzip_filter_inflate(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx);
+static ngx_int_t ngx_http_gunzip_filter_inflate_end(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx);
+
+static void *ngx_http_gunzip_filter_alloc(void *opaque, u_int items,
+ u_int size);
+static void ngx_http_gunzip_filter_free(void *opaque, void *address);
+
+static ngx_int_t ngx_http_gunzip_filter_init(ngx_conf_t *cf);
+static void *ngx_http_gunzip_create_conf(ngx_conf_t *cf);
+static char *ngx_http_gunzip_merge_conf(ngx_conf_t *cf,
+ void *parent, void *child);
+
+
+static ngx_command_t ngx_http_gunzip_filter_commands[] = {
+
+ { ngx_string("gunzip"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_gunzip_conf_t, enable),
+ NULL },
+
+ { ngx_string("gunzip_buffers"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
+ ngx_conf_set_bufs_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_gunzip_conf_t, bufs),
+ NULL },
+
+ ngx_null_command
+};
+
+
+static ngx_http_module_t ngx_http_gunzip_filter_module_ctx = {
+ NULL, /* preconfiguration */
+ ngx_http_gunzip_filter_init, /* postconfiguration */
+
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
+
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_gunzip_create_conf, /* create location configuration */
+ ngx_http_gunzip_merge_conf /* merge location configuration */
+};
+
+
+ngx_module_t ngx_http_gunzip_filter_module = {
+ NGX_MODULE_V1,
+ &ngx_http_gunzip_filter_module_ctx, /* module context */
+ ngx_http_gunzip_filter_commands, /* module directives */
+ NGX_HTTP_MODULE, /* module type */
+ NULL, /* init master */
+ NULL, /* init module */
+ NULL, /* init process */
+ NULL, /* init thread */
+ NULL, /* exit thread */
+ NULL, /* exit process */
+ NULL, /* exit master */
+ NGX_MODULE_V1_PADDING
+};
+
+
+static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
+static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
+
+
+static ngx_int_t
+ngx_http_gunzip_header_filter(ngx_http_request_t *r)
+{
+ ngx_http_gunzip_ctx_t *ctx;
+ ngx_http_gunzip_conf_t *conf;
+
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_gunzip_filter_module);
+
+ /* TODO support multiple content-codings */
+ /* TODO always gunzip - due to configuration or module request */
+ /* TODO ignore content encoding? */
+
+ if (!conf->enable
+ || r->headers_out.content_encoding == NULL
+ || r->headers_out.content_encoding->value.len != 4
+ || ngx_strncasecmp(r->headers_out.content_encoding->value.data,
+ (u_char *) "gzip", 4) != 0)
+ {
+ return ngx_http_next_header_filter(r);
+ }
+
+ r->gzip_vary = 1;
+
+ if (!r->gzip_tested) {
+ if (ngx_http_gzip_ok(r) == NGX_OK) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ } else if (!r->gzip_ok) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gunzip_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_gunzip_filter_module);
+
+ ctx->request = r;
+
+ r->filter_need_in_memory = 1;
+
+ r->headers_out.content_encoding->hash = 0;
+ r->headers_out.content_encoding = NULL;
+
+ ngx_http_clear_content_length(r);
+ ngx_http_clear_accept_ranges(r);
+
+ return ngx_http_next_header_filter(r);
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
+{
+ int rc;
+ ngx_chain_t *cl;
+ ngx_http_gunzip_ctx_t *ctx;
+
+ ctx = ngx_http_get_module_ctx(r, ngx_http_gunzip_filter_module);
+
+ if (ctx == NULL || ctx->done) {
+ return ngx_http_next_body_filter(r, in);
+ }
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http gunzip filter");
+
+ if (!ctx->started) {
+ if (ngx_http_gunzip_filter_inflate_start(r, ctx) != NGX_OK) {
+ goto failed;
+ }
+ }
+
+ if (in) {
+ if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) {
+ goto failed;
+ }
+ }
+
+ if (ctx->nomem) {
+
+ /* flush busy buffers */
+
+ if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) {
+ goto failed;
+ }
+
+ cl = NULL;
+
+ ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &cl,
+ (ngx_buf_tag_t) &ngx_http_gunzip_filter_module);
+ ctx->nomem = 0;
+ }
+
+ for ( ;; ) {
+
+ /* cycle while we can write to a client */
+
+ for ( ;; ) {
+
+ /* cycle while there is data to feed zlib and ... */
+
+ rc = ngx_http_gunzip_filter_add_data(r, ctx);
+
+ if (rc == NGX_DECLINED) {
+ break;
+ }
+
+ if (rc == NGX_AGAIN) {
+ continue;
+ }
+
+
+ /* ... there are buffers to write zlib output */
+
+ rc = ngx_http_gunzip_filter_get_buf(r, ctx);
+
+ if (rc == NGX_DECLINED) {
+ break;
+ }
+
+ if (rc == NGX_ERROR) {
+ goto failed;
+ }
+
+ rc = ngx_http_gunzip_filter_inflate(r, ctx);
+
+ if (rc == NGX_OK) {
+ break;
+ }
+
+ if (rc == NGX_ERROR) {
+ goto failed;
+ }
+
+ /* rc == NGX_AGAIN */
+ }
+
+ if (ctx->out == NULL) {
+ return ctx->busy ? NGX_AGAIN : NGX_OK;
+ }
+
+ rc = ngx_http_next_body_filter(r, ctx->out);
+
+ if (rc == NGX_ERROR) {
+ goto failed;
+ }
+
+ ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &ctx->out,
+ (ngx_buf_tag_t) &ngx_http_gunzip_filter_module);
+ ctx->last_out = &ctx->out;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "gunzip out: %p", ctx->out);
+
+ ctx->nomem = 0;
+
+ if (ctx->done) {
+ return rc;
+ }
+ }
+
+ /* unreachable */
+
+failed:
+
+ ctx->done = 1;
+
+ return NGX_ERROR;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_inflate_start(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx)
+{
+ int rc;
+
+ ctx->zstream.next_in = Z_NULL;
+ ctx->zstream.avail_in = 0;
+
+ ctx->zstream.zalloc = ngx_http_gunzip_filter_alloc;
+ ctx->zstream.zfree = ngx_http_gunzip_filter_free;
+ ctx->zstream.opaque = ctx;
+
+ /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */
+ rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16);
+
+ if (rc != Z_OK) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "inflateInit2() failed: %d", rc);
+ return NGX_ERROR;
+ }
+
+ ctx->started = 1;
+
+ ctx->last_out = &ctx->out;
+ ctx->flush = Z_NO_FLUSH;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_add_data(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx)
+{
+ if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) {
+ return NGX_OK;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "gunzip in: %p", ctx->in);
+
+ if (ctx->in == NULL) {
+ return NGX_DECLINED;
+ }
+
+ ctx->in_buf = ctx->in->buf;
+ ctx->in = ctx->in->next;
+
+ ctx->zstream.next_in = ctx->in_buf->pos;
+ ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
+
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "gunzip in_buf:%p ni:%p ai:%ud",
+ ctx->in_buf,
+ ctx->zstream.next_in, ctx->zstream.avail_in);
+
+ if (ctx->in_buf->last_buf || ctx->in_buf->last_in_chain) {
+ ctx->flush = Z_FINISH;
+
+ } else if (ctx->in_buf->flush) {
+ ctx->flush = Z_SYNC_FLUSH;
+
+ } else if (ctx->zstream.avail_in == 0) {
+ /* ctx->flush == Z_NO_FLUSH */
+ return NGX_AGAIN;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_get_buf(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx)
+{
+ ngx_http_gunzip_conf_t *conf;
+
+ if (ctx->zstream.avail_out) {
+ return NGX_OK;
+ }
+
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_gunzip_filter_module);
+
+ if (ctx->free) {
+ ctx->out_buf = ctx->free->buf;
+ ctx->free = ctx->free->next;
+
+ ctx->out_buf->flush = 0;
+
+ } else if (ctx->bufs < conf->bufs.num) {
+
+ ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size);
+ if (ctx->out_buf == NULL) {
+ return NGX_ERROR;
+ }
+
+ ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gunzip_filter_module;
+ ctx->out_buf->recycled = 1;
+ ctx->bufs++;
+
+ } else {
+ ctx->nomem = 1;
+ return NGX_DECLINED;
+ }
+
+ ctx->zstream.next_out = ctx->out_buf->pos;
+ ctx->zstream.avail_out = conf->bufs.size;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_inflate(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx)
+{
+ int rc;
+ ngx_buf_t *b;
+ ngx_chain_t *cl;
+
+ ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "inflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
+ ctx->zstream.next_in, ctx->zstream.next_out,
+ ctx->zstream.avail_in, ctx->zstream.avail_out,
+ ctx->flush, ctx->redo);
+
+ rc = inflate(&ctx->zstream, ctx->flush);
+
+ if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "inflate() failed: %d, %d", ctx->flush, rc);
+ return NGX_ERROR;
+ }
+
+ ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "inflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
+ ctx->zstream.next_in, ctx->zstream.next_out,
+ ctx->zstream.avail_in, ctx->zstream.avail_out,
+ rc);
+
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "gunzip in_buf:%p pos:%p",
+ ctx->in_buf, ctx->in_buf->pos);
+
+ if (ctx->zstream.next_in) {
+ ctx->in_buf->pos = ctx->zstream.next_in;
+
+ if (ctx->zstream.avail_in == 0) {
+ ctx->zstream.next_in = NULL;
+ }
+ }
+
+ ctx->out_buf->last = ctx->zstream.next_out;
+
+ if (ctx->zstream.avail_out == 0) {
+
+ /* zlib wants to output some more data */
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = ctx->out_buf;
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+
+ ctx->redo = 1;
+
+ return NGX_AGAIN;
+ }
+
+ ctx->redo = 0;
+
+ if (ctx->flush == Z_SYNC_FLUSH) {
+
+ ctx->flush = Z_NO_FLUSH;
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ b = ctx->out_buf;
+
+ if (ngx_buf_size(b) == 0) {
+
+ b = ngx_calloc_buf(ctx->request->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ } else {
+ ctx->zstream.avail_out = 0;
+ }
+
+ b->flush = 1;
+
+ cl->buf = b;
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+
+ return NGX_OK;
+ }
+
+ if (rc == Z_STREAM_END && ctx->flush == Z_FINISH
+ && ctx->zstream.avail_in == 0)
+ {
+
+ if (ngx_http_gunzip_filter_inflate_end(r, ctx) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+ }
+
+ if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) {
+
+ rc = inflateReset(&ctx->zstream);
+
+ if (rc != Z_OK) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "inflateReset() failed: %d", rc);
+ return NGX_ERROR;
+ }
+
+ ctx->redo = 1;
+
+ return NGX_AGAIN;
+ }
+
+ if (ctx->in == NULL) {
+
+ b = ctx->out_buf;
+
+ if (ngx_buf_size(b) == 0) {
+ return NGX_OK;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ ctx->zstream.avail_out = 0;
+
+ cl->buf = b;
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+
+ return NGX_OK;
+ }
+
+ return NGX_AGAIN;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_inflate_end(ngx_http_request_t *r,
+ ngx_http_gunzip_ctx_t *ctx)
+{
+ int rc;
+ ngx_buf_t *b;
+ ngx_chain_t *cl;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "gunzip inflate end");
+
+ rc = inflateEnd(&ctx->zstream);
+
+ if (rc != Z_OK) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "inflateEnd() failed: %d", rc);
+ return NGX_ERROR;
+ }
+
+ b = ctx->out_buf;
+
+ if (ngx_buf_size(b) == 0) {
+
+ b = ngx_calloc_buf(ctx->request->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+
+ b->last_buf = (r == r->main) ? 1 : 0;
+ b->last_in_chain = 1;
+ b->sync = 1;
+
+ ctx->done = 1;
+
+ return NGX_OK;
+}
+
+
+static void *
+ngx_http_gunzip_filter_alloc(void *opaque, u_int items, u_int size)
+{
+ ngx_http_gunzip_ctx_t *ctx = opaque;
+
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
+ "gunzip alloc: n:%ud s:%ud",
+ items, size);
+
+ return ngx_palloc(ctx->request->pool, items * size);
+}
+
+
+static void
+ngx_http_gunzip_filter_free(void *opaque, void *address)
+{
+#if 0
+ ngx_http_gunzip_ctx_t *ctx = opaque;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
+ "gunzip free: %p", address);
+#endif
+}
+
+
+static void *
+ngx_http_gunzip_create_conf(ngx_conf_t *cf)
+{
+ ngx_http_gunzip_conf_t *conf;
+
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gunzip_conf_t));
+ if (conf == NULL) {
+ return NULL;
+ }
+
+ /*
+ * set by ngx_pcalloc():
+ *
+ * conf->bufs.num = 0;
+ */
+
+ conf->enable = NGX_CONF_UNSET;
+
+ return conf;
+}
+
+
+static char *
+ngx_http_gunzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
+{
+ ngx_http_gunzip_conf_t *prev = parent;
+ ngx_http_gunzip_conf_t *conf = child;
+
+ ngx_conf_merge_value(conf->enable, prev->enable, 0);
+
+ ngx_conf_merge_bufs_value(conf->bufs, prev->bufs,
+ (128 * 1024) / ngx_pagesize, ngx_pagesize);
+
+ return NGX_CONF_OK;
+}
+
+
+static ngx_int_t
+ngx_http_gunzip_filter_init(ngx_conf_t *cf)
+{
+ ngx_http_next_header_filter = ngx_http_top_header_filter;
+ ngx_http_top_header_filter = ngx_http_gunzip_header_filter;
+
+ ngx_http_next_body_filter = ngx_http_top_body_filter;
+ ngx_http_top_body_filter = ngx_http_gunzip_body_filter;
+
+ return NGX_OK;
+}
diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
index da359766d..6e777619b 100644
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -10,8 +10,13 @@
#include <ngx_http.h>
+#define NGX_HTTP_GZIP_STATIC_OFF 0
+#define NGX_HTTP_GZIP_STATIC_ON 1
+#define NGX_HTTP_GZIP_STATIC_ALWAYS 2
+
+
typedef struct {
- ngx_flag_t enable;
+ ngx_uint_t enable;
} ngx_http_gzip_static_conf_t;
@@ -22,14 +27,22 @@ static char *ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent,
static ngx_int_t ngx_http_gzip_static_init(ngx_conf_t *cf);
+static ngx_conf_enum_t ngx_http_gzip_static[] = {
+ { ngx_string("off"), NGX_HTTP_GZIP_STATIC_OFF },
+ { ngx_string("on"), NGX_HTTP_GZIP_STATIC_ON },
+ { ngx_string("always"), NGX_HTTP_GZIP_STATIC_ALWAYS },
+ { ngx_null_string, 0 }
+};
+
+
static ngx_command_t ngx_http_gzip_static_commands[] = {
{ ngx_string("gzip_static"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
+ ngx_conf_set_enum_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_static_conf_t, enable),
- NULL },
+ &ngx_http_gzip_static },
ngx_null_command
};
@@ -92,11 +105,17 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
gzcf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_static_module);
- if (!gzcf->enable) {
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_OFF) {
return NGX_DECLINED;
}
- rc = ngx_http_gzip_ok(r);
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) {
+ rc = ngx_http_gzip_ok(r);
+
+ } else {
+ /* always */
+ rc = NGX_OK;
+ }
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
@@ -169,10 +188,12 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
return NGX_DECLINED;
}
- r->gzip_vary = 1;
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) {
+ r->gzip_vary = 1;
- if (rc != NGX_OK) {
- return NGX_DECLINED;
+ if (rc != NGX_OK) {
+ return NGX_DECLINED;
+ }
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd);
@@ -274,7 +295,7 @@ ngx_http_gzip_static_create_conf(ngx_conf_t *cf)
return NULL;
}
- conf->enable = NGX_CONF_UNSET;
+ conf->enable = NGX_CONF_UNSET_UINT;
return conf;
}
@@ -286,7 +307,8 @@ ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_gzip_static_conf_t *prev = parent;
ngx_http_gzip_static_conf_t *conf = child;
- ngx_conf_merge_value(conf->enable, prev->enable, 0);
+ ngx_conf_merge_uint_value(conf->enable, prev->enable,
+ NGX_HTTP_GZIP_STATIC_OFF);
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c
index 3f9910e71..31a8b987a 100644
--- a/src/http/modules/ngx_http_limit_req_module.c
+++ b/src/http/modules/ngx_http_limit_req_module.c
@@ -444,17 +444,17 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
node->key = hash;
- ngx_rbtree_insert(&ctx->sh->rbtree, node);
-
lr = (ngx_http_limit_req_node_t *) &node->color;
- ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
-
lr->len = (u_char) len;
lr->excess = 0;
ngx_memcpy(lr->data, data, len);
+ ngx_rbtree_insert(&ctx->sh->rbtree, node);
+
+ ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
+
if (account) {
lr->last = now;
lr->count = 0;
diff --git a/src/http/modules/ngx_http_map_module.c b/src/http/modules/ngx_http_map_module.c
index 54f9ec445..371737b2e 100644
--- a/src/http/modules/ngx_http_map_module.c
+++ b/src/http/modules/ngx_http_map_module.c
@@ -369,7 +369,7 @@ static char *
ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_int_t rc, index;
- ngx_str_t *value, file, name;
+ ngx_str_t *value, name;
ngx_uint_t i, key;
ngx_http_map_conf_ctx_t *ctx;
ngx_http_variable_value_t *var, **vp;
@@ -391,15 +391,7 @@ ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
}
if (ngx_strcmp(value[0].data, "include") == 0) {
- file = value[1];
-
- if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
-
- return ngx_conf_parse(cf, &file);
+ return ngx_conf_include(cf, dummy, conf);
}
if (value[1].data[0] == '$') {
diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c
index 5077ded9a..b756c93e5 100644
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -13,6 +13,7 @@
typedef struct {
ngx_http_upstream_conf_t upstream;
ngx_int_t index;
+ ngx_uint_t gzip_flag;
} ngx_http_memcached_loc_conf_t;
@@ -101,6 +102,13 @@ static ngx_command_t ngx_http_memcached_commands[] = {
offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream),
&ngx_http_memcached_next_upstream_masks },
+ { ngx_string("memcached_gzip_flag"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_memcached_loc_conf_t, gzip_flag),
+ NULL },
+
ngx_null_command
};
@@ -281,10 +289,13 @@ ngx_http_memcached_reinit_request(ngx_http_request_t *r)
static ngx_int_t
ngx_http_memcached_process_header(ngx_http_request_t *r)
{
- u_char *p, *len;
- ngx_str_t line;
- ngx_http_upstream_t *u;
- ngx_http_memcached_ctx_t *ctx;
+ u_char *p, *start;
+ ngx_str_t line;
+ ngx_uint_t flags;
+ ngx_table_elt_t *h;
+ ngx_http_upstream_t *u;
+ ngx_http_memcached_ctx_t *ctx;
+ ngx_http_memcached_loc_conf_t *mlcf;
u = r->upstream;
@@ -309,6 +320,7 @@ found:
p = u->buffer.pos;
ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module);
+ mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) {
@@ -329,23 +341,56 @@ found:
goto no_valid;
}
- /* skip flags */
+ /* flags */
+
+ start = p;
while (*p) {
if (*p++ == ' ') {
- goto length;
+ if (mlcf->gzip_flag) {
+ goto flags;
+ } else {
+ goto length;
+ }
}
}
goto no_valid;
+ flags:
+
+ flags = ngx_atoi(start, p - start - 1);
+
+ if (flags == (ngx_uint_t) NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "memcached sent invalid flags in response \"%V\" "
+ "for key \"%V\"",
+ &line, &ctx->key);
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
+ }
+
+ if (flags & mlcf->gzip_flag) {
+ h = ngx_list_push(&r->headers_out.headers);
+ if (h == NULL) {
+ return NGX_ERROR;
+ }
+
+ h->hash = 1;
+ h->key.len = sizeof("Content-Encoding") - 1;
+ h->key.data = (u_char *) "Content-Encoding";
+ h->value.len = sizeof("gzip") - 1;
+ h->value.data = (u_char *) "gzip";
+
+ r->headers_out.content_encoding = h;
+ }
+
length:
- len = p;
+ start = p;
while (*p && *p++ != CR) { /* void */ }
- u->headers_in.content_length_n = ngx_atoof(len, p - len - 1);
+ u->headers_in.content_length_n = ngx_atoof(start, p - start - 1);
if (u->headers_in.content_length_n == -1) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"memcached sent invalid length in response \"%V\" "
@@ -550,6 +595,7 @@ ngx_http_memcached_create_loc_conf(ngx_conf_t *cf)
conf->upstream.pass_request_body = 0;
conf->index = NGX_CONF_UNSET;
+ conf->gzip_flag = NGX_CONF_UNSET_UINT;
return conf;
}
@@ -593,6 +639,8 @@ ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->index = prev->index;
}
+ ngx_conf_merge_uint_value(conf->gzip_flag, prev->gzip_flag, 0);
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index 7c2972cd9..67a6dea43 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -50,7 +50,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
-our $VERSION = '1.3.5';
+our $VERSION = '1.3.6';
require XSLoader;
XSLoader::load('nginx', $VERSION);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 8667ae985..826e4e5b5 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2776,7 +2776,15 @@ ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
family = AF_INET;
- inaddr = *(in_addr_t *) &inaddr6->s6_addr[12];
+
+ p = inaddr6->s6_addr;
+
+ inaddr = p[12] << 24;
+ inaddr += p[13] << 16;
+ inaddr += p[14] << 8;
+ inaddr += p[15];
+
+ inaddr = htonl(inaddr);
}
}
#endif
@@ -3236,7 +3244,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_http_core_loc_conf_t *clcf = conf;
- ngx_str_t *value, *content_type, *old, file;
+ ngx_str_t *value, *content_type, *old;
ngx_uint_t i, n, hash;
ngx_hash_key_t *type;
@@ -3249,15 +3257,8 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
" in \"include\" directive");
return NGX_CONF_ERROR;
}
- file = value[1];
-
- if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
- return ngx_conf_parse(cf, &file);
+ return ngx_conf_include(cf, dummy, conf);
}
content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
index 72b1f9b2f..fd44bc659 100644
--- a/src/http/ngx_http_write_filter_module.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -185,18 +185,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if (size == 0 && !(c->buffered & NGX_LOWLEVEL_BUFFERED)) {
- if (last) {
- r->out = NULL;
- c->buffered &= ~NGX_HTTP_WRITE_BUFFERED;
-
- return NGX_OK;
- }
-
- if (flush) {
- do {
- r->out = r->out->next;
- } while (r->out);
+ if (last || flush) {
+ for (cl = r->out; cl; /* void */) {
+ ln = cl;
+ cl = cl->next;
+ ngx_free_chain(r->pool, ln);
+ }
+ r->out = NULL;
c->buffered &= ~NGX_HTTP_WRITE_BUFFERED;
return NGX_OK;