diff src/http/ngx_http_copy_filter_module.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents
children b55cbf18157e
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -0,0 +1,140 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+typedef struct {
+    ngx_bufs_t  bufs;
+} ngx_http_copy_filter_conf_t;
+
+
+static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
+static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
+    void *parent, void *child);
+static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle);
+
+
+static ngx_command_t  ngx_http_copy_filter_commands[] = {
+
+    { ngx_string("output_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_copy_filter_conf_t, bufs),
+      NULL },
+
+      ngx_null_command
+};
+
+
+static ngx_http_module_t  ngx_http_copy_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
+    NULL,                                  /* create main configuration */
+    NULL,                                  /* init main configuration */
+
+    NULL,                                  /* create server configuration */
+    NULL,                                  /* merge server configuration */
+
+    ngx_http_copy_filter_create_conf,      /* create location configuration */
+    ngx_http_copy_filter_merge_conf        /* merge location configuration */
+};
+
+
+ngx_module_t  ngx_http_copy_filter_module = {
+    NGX_MODULE,
+    &ngx_http_copy_filter_module_ctx,      /* module context */
+    ngx_http_copy_filter_commands,         /* module directives */
+    NGX_HTTP_MODULE,                       /* module type */
+    ngx_http_copy_filter_init,             /* init module */
+    NULL                                   /* init process */
+};
+
+
+static ngx_http_output_body_filter_pt    ngx_http_next_filter;
+
+
+static ngx_int_t
+ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
+{
+    ngx_output_chain_ctx_t       *ctx;
+    ngx_http_copy_filter_conf_t  *conf;
+
+    if (r->connection->write->error) {
+        return NGX_ERROR;
+    }
+
+    ctx = ngx_http_get_module_ctx(r->main ? r->main : r,
+                                            ngx_http_copy_filter_module);
+
+    if (ctx == NULL) {
+        conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
+                                            ngx_http_copy_filter_module);
+
+        ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+        if (ctx == NULL) {
+            return NGX_ERROR;
+        }
+
+        ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
+
+        ctx->sendfile = r->connection->sendfile;
+        ctx->need_in_memory = r->filter_need_in_memory;
+        ctx->need_in_temp = r->filter_need_temporary;
+
+        ctx->pool = r->pool;
+        ctx->bufs = conf->bufs;
+        ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module;
+
+        ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter;
+        ctx->filter_ctx = r;
+
+    }
+
+    return ngx_output_chain(ctx, in);
+}
+
+
+static void *
+ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
+{
+    ngx_http_copy_filter_conf_t *conf;
+
+    conf = ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t));
+    if (conf == NULL) {
+        return NULL;
+    }
+
+    conf->bufs.num = 0;
+
+    return conf;
+}
+
+
+static char *
+ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
+{
+    ngx_http_copy_filter_conf_t *prev = parent;
+    ngx_http_copy_filter_conf_t *conf = child;
+
+    ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 1, 32768);
+
+    return NULL;
+}
+
+
+static ngx_int_t
+ngx_http_copy_filter_init(ngx_cycle_t *cycle)
+{
+    ngx_http_next_filter = ngx_http_top_body_filter;
+    ngx_http_top_body_filter = ngx_http_copy_filter;
+
+    return NGX_OK;
+}
+