~ubuntu-branches/ubuntu/natty/nginx/natty-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/src/ngx_http_lua_filter.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Lustfield, Micheal Lustfield, Kartik Mistry
  • Date: 2011-03-03 23:39:07 UTC
  • mfrom: (4.2.29 sid)
  • Revision ID: james.westby@ubuntu.com-20110303233907-y48yifhfnn5qjuxz
Tags: 0.8.54-4
[Micheal Lustfield]
* debian/nginx-{full,light,extras}.default:
  + Added comment about alternative to ULIMIT.
* debian/nginx-{full,light,extras}.init.d:
  + Added quotes around a test variable. (Closes: #610946, LP: #699736)
* debian/patches/609343-log-time-iso8601.diff:
  + Added patch to add $time_iso8601 variable to logs. (Closes: #609343)
* Clean up old logrotate files. (Closes: #608983, Closes: #610289)
  + Added Files:
    - debian/nginx-common.preinst
  + Modified Files:
    - debian/rules
  + Moved debian/nginx-common.logrotate to debian/logrotate.
* Added common files to nginx-common package. (Closes: #610290)
  + Removed Files:
    - debian/nginx-full.dirs
    - debian/nginx-light.dirs
    - debian/nginx-full.install
    - debian/nginx-light.install
    - debian/nginx-extras.install
    - debian/nginx.*
  + Added Files:
    - debian/nginx-common.default
    - debian/nginx-common.dirs
    - debian/nginx-common.init.d
    - debian/nginx-common.install
    - debian/nginx-common.manpages
    - debian/logrotate
  + Modified Files:
    - debian/nginx-extras.dirs
    - debian/control
    - debian/rules
* debian/nginx-*.install: (Closes: #609797)
  + Removed NEWS.Debian from nginx-{full,light,extras}.install.
  + Added NEWS.Debian to nginx-common.install.
* nginx-common.postinst:
  + Enforce /var/log/nginx mode and user:group. (Closes: #610983)
  + Enforce /var/log/nginx/*.log mode and user:group. (Closes: #612832)
* debian/rules:
  + Added --with-file-aio to nginx-extras. (Closes: #613175)
  + Removed split clients and user id modules from nginx-light.
* debian/conf/sites-available/default:
  + Fixed a minor typo ( s/Quickstart/QuickStart/ ). (Closes: #613355)
* debian/conf/mime.types:
  + Changed xml type to application/xhtml+xml. (Closes: #613851)
* debian/help/docs/fcgiwrap:
  + Removed Ubuntu specific line in docs. (Closes: #614987)
* debian/conf/sites-available/default:
  + Fixed a pointer to a file. (Closes: #614980)

[Kartik Mistry]
* debian/*.lintian-overrides:
  + Add Lintian overrides for nginx man page. We've manpage in nginx-common
    binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
 
2
#include "ngx_http_lua_filter.h"
 
3
#include "ngx_http_lua_util.h"
 
4
 
 
5
ngx_http_output_header_filter_pt ngx_http_lua_next_header_filter;
 
6
ngx_http_output_body_filter_pt ngx_http_lua_next_body_filter;
 
7
 
 
8
static ngx_int_t ngx_http_lua_header_filter(ngx_http_request_t *r);
 
9
static ngx_int_t ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in);
 
10
static ngx_int_t ngx_http_lua_rewrite_phase_handler(ngx_http_request_t *r);
 
11
static void ngx_http_lua_post_read(ngx_http_request_t *r);
 
12
 
 
13
ngx_int_t
 
14
ngx_http_lua_filter_init(ngx_conf_t *cf)
 
15
{
 
16
    ngx_http_handler_pt         *h;
 
17
    ngx_http_core_main_conf_t   *cmcf;
 
18
 
 
19
    /* setting up rewrite phase handler to force reading request body */
 
20
    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
21
    h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
 
22
 
 
23
    if (h == NULL) {
 
24
        return NGX_ERROR;
 
25
    }
 
26
 
 
27
    *h = ngx_http_lua_rewrite_phase_handler;
 
28
 
 
29
    /* setting up output filters to intercept subrequest responses */
 
30
    ngx_http_lua_next_header_filter = ngx_http_top_header_filter;
 
31
    ngx_http_top_header_filter = ngx_http_lua_header_filter;
 
32
 
 
33
    ngx_http_lua_next_body_filter = ngx_http_top_body_filter;
 
34
    ngx_http_top_body_filter = ngx_http_lua_body_filter;
 
35
 
 
36
    return NGX_OK;
 
37
}
 
38
 
 
39
static ngx_int_t
 
40
ngx_http_lua_header_filter(ngx_http_request_t *r)
 
41
{
 
42
    ngx_http_lua_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
43
 
 
44
    if (ctx && ctx->capture) {
 
45
        /* force subrequest response body buffer in memory */
 
46
        r->filter_need_in_memory = 1;
 
47
 
 
48
        return NGX_OK;
 
49
    }
 
50
 
 
51
    return ngx_http_lua_next_header_filter(r);
 
52
}
 
53
 
 
54
static ngx_int_t
 
55
ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
56
{
 
57
    int rc;
 
58
    ngx_http_lua_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
59
 
 
60
    if (!ctx || !ctx->capture) {
 
61
        return ngx_http_lua_next_body_filter(r, in);
 
62
    }
 
63
 
 
64
    rc = ngx_http_lua_add_copy_chain(r->pool,
 
65
            &ctx->body, in);
 
66
 
 
67
    if (rc != NGX_OK) {
 
68
        return NGX_ERROR;
 
69
    }
 
70
 
 
71
    ngx_http_lua_discard_bufs(r->pool, in);
 
72
 
 
73
    return NGX_OK;
 
74
}
 
75
 
 
76
static ngx_int_t
 
77
ngx_http_lua_rewrite_phase_handler(ngx_http_request_t *r)
 
78
{
 
79
    ngx_http_lua_loc_conf_t *llcf;
 
80
    ngx_http_lua_ctx_t      *ctx;
 
81
    ngx_int_t               rc;
 
82
 
 
83
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
84
 
 
85
    if (!llcf->force_read_body) {
 
86
        dd("no need to reading request body");
 
87
        return NGX_DECLINED;
 
88
    }
 
89
 
 
90
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
91
 
 
92
    if (ctx != NULL) {
 
93
        if (ctx->read_body_done) {
 
94
            dd("request body has been read");
 
95
            return NGX_DECLINED;
 
96
        }
 
97
        return NGX_AGAIN;
 
98
    }
 
99
 
 
100
    if (r->method != NGX_HTTP_POST && r->method != NGX_HTTP_PUT) {
 
101
        dd("request method should not have a body: %d", (int) r->method);
 
102
        return NGX_DECLINED;
 
103
    }
 
104
 
 
105
    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_lua_ctx_t));
 
106
 
 
107
    if (ctx == NULL) {
 
108
        return NGX_ERROR;
 
109
    }
 
110
 
 
111
    ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
 
112
 
 
113
    dd("start to read request body");
 
114
 
 
115
    rc = ngx_http_read_client_request_body(r, ngx_http_lua_post_read);
 
116
 
 
117
    if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
 
118
        return rc;
 
119
    }
 
120
 
 
121
    if (rc == NGX_AGAIN) {
 
122
        ctx->waiting_more_body = 1;
 
123
        return NGX_AGAIN;
 
124
    }
 
125
 
 
126
    return NGX_DECLINED;
 
127
}
 
128
 
 
129
static void
 
130
ngx_http_lua_post_read(ngx_http_request_t *r)
 
131
{
 
132
    ngx_http_lua_ctx_t  *ctx;
 
133
 
 
134
    r->read_event_handler = ngx_http_request_empty_handler;
 
135
 
 
136
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
137
 
 
138
    ctx->read_body_done = 1;
 
139
 
 
140
#if defined(nginx_version) && nginx_version >= 8011
 
141
    r->main->count--;
 
142
#endif
 
143
 
 
144
    if (ctx->waiting_more_body) {
 
145
        ctx->waiting_more_body = 0;
 
146
        ngx_http_core_run_phases(r);
 
147
    }
 
148
}
 
149