~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2011-04-16 13:47:58 UTC
  • mfrom: (4.2.31 sid)
  • Revision ID: james.westby@ubuntu.com-20110416134758-yqca2qp5crh2hw2f
Tags: 1.0.0-2
* debian/rules:
  + Removed --with-file-aio support. Fixed FTBFS on kFreeBSD-* arch
    (Closes: #621882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
 
2
 
2
3
#define DDEBUG 0
3
4
 
 
5
#include "nginx.h"
4
6
#include "ngx_http_lua_contentby.h"
5
7
#include "ngx_http_lua_util.h"
6
8
#include "ngx_http_lua_hook.h"
7
 
 
8
 
static void ngx_http_lua_request_cleanup(void *data);
9
 
static ngx_int_t ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
10
 
        ngx_http_lua_ctx_t *ctx, int nret);
 
9
#include "ngx_http_lua_cache.h"
 
10
 
 
11
 
 
12
static void ngx_http_lua_content_phase_post_read(ngx_http_request_t *r);
11
13
 
12
14
 
13
15
ngx_int_t
18
20
    ngx_http_lua_ctx_t      *ctx;
19
21
    ngx_http_cleanup_t      *cln;
20
22
 
 
23
    dd("content by chunk");
 
24
 
 
25
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
26
 
 
27
    if (ctx == NULL) {
 
28
        ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_lua_ctx_t));
 
29
        if (ctx == NULL) {
 
30
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
31
        }
 
32
 
 
33
        dd("setting new ctx, ctx = %p", ctx);
 
34
 
 
35
        ctx->cc_ref = LUA_NOREF;
 
36
 
 
37
        ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
 
38
 
 
39
    } else {
 
40
        dd("reset ctx");
 
41
        ngx_http_lua_reset_ctx(r, L, ctx);
 
42
    }
 
43
 
 
44
    ctx->entered_content_phase = 1;
 
45
 
21
46
    /*  {{{ new coroutine to handle request */
22
47
    cc = ngx_http_lua_new_thread(r, L, &cc_ref);
 
48
 
23
49
    if (cc == NULL) {
24
50
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
25
 
                "(lua-content-by-chunk) failed to create new coroutine to handle request!");
 
51
                "(lua-content-by-chunk) failed to create new coroutine "
 
52
                "to handle request");
 
53
 
26
54
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
27
55
    }
28
56
 
42
70
    lua_setglobal(cc, GLOBALS_SYMBOL_REQUEST);
43
71
    /*  }}} */
44
72
 
45
 
    /*  {{{ initialize request context */
46
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
47
 
    if (ctx == NULL) {
48
 
        ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_lua_ctx_t));
49
 
        if (ctx == NULL) {
50
 
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
51
 
        }
52
 
 
53
 
        ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
54
 
    }
55
 
 
56
73
    ctx->cc = cc;
57
74
    ctx->cc_ref = cc_ref;
58
75
 
59
 
    /*  }}} */
60
 
 
61
76
    /*  {{{ register request cleanup hooks */
62
 
    cln = ngx_http_cleanup_add(r, 0);
63
 
    if (cln == NULL) {
64
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
77
    if (ctx->cleanup == NULL) {
 
78
        cln = ngx_http_cleanup_add(r, 0);
 
79
        if (cln == NULL) {
 
80
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
81
        }
 
82
 
 
83
        cln->handler = ngx_http_lua_request_cleanup;
 
84
        cln->data = r;
 
85
        ctx->cleanup = &cln->handler;
65
86
    }
66
 
 
67
 
    cln->handler = ngx_http_lua_request_cleanup;
68
 
    cln->data = r;
69
 
    ctx->cleanup = &cln->handler;
70
87
    /*  }}} */
71
88
 
72
89
    return ngx_http_lua_run_thread(L, r, ctx, 0);
73
90
}
74
91
 
75
92
 
76
 
static ngx_int_t
77
 
ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
78
 
        ngx_http_lua_ctx_t *ctx, int nret)
79
 
{
80
 
    int                      rc;
81
 
    int                      cc_ref;
82
 
    lua_State               *cc;
83
 
    const char              *err, *msg;
84
 
 
85
 
    /* set Lua VM panic handler */
86
 
    lua_atpanic(L, ngx_http_lua_atpanic);
87
 
 
88
 
    NGX_LUA_EXCEPTION_TRY {
89
 
        cc = ctx->cc;
90
 
        cc_ref = ctx->cc_ref;
91
 
 
92
 
        /*  run code */
93
 
        rc = lua_resume(cc, nret);
94
 
 
95
 
        dd("lua resume returns %d", (int) rc);
96
 
 
97
 
        switch (rc) {
98
 
            case LUA_YIELD:
99
 
                /*  yielded, let event handler do the rest job */
100
 
                /*  FIXME: add io cmd dispatcher here */
101
 
                lua_settop(cc, 0);
102
 
                return NGX_AGAIN;
103
 
                break;
104
 
 
105
 
            case 0:
106
 
                /*  normal end */
107
 
                ngx_http_lua_del_thread(r, L, cc_ref, 0);
108
 
 
109
 
                if (ctx->cleanup) {
110
 
                    dd("cleaning up cleanup");
111
 
                    *ctx->cleanup = NULL;
112
 
                    ctx->cleanup = NULL;
113
 
                }
114
 
 
115
 
                ngx_http_lua_send_chain_link(r, ctx, NULL /* indicate last_buf */);
116
 
                return NGX_OK;
117
 
                break;
118
 
 
119
 
            case LUA_ERRRUN:
120
 
                err = "runtime error";
121
 
                break;
122
 
 
123
 
            case LUA_ERRSYNTAX:
124
 
                err = "syntax error";
125
 
                break;
126
 
 
127
 
            case LUA_ERRMEM:
128
 
                err = "memory allocation error";
129
 
                break;
130
 
 
131
 
            case LUA_ERRERR:
132
 
                err = "error handler error";
133
 
                break;
134
 
 
135
 
            default:
136
 
                err = "unknown error";
137
 
                break;
138
 
        }
139
 
 
140
 
        if (lua_isstring(cc, -1)) {
141
 
            dd("user custom error msg");
142
 
            msg = lua_tostring(cc, -1);
143
 
 
144
 
        } else {
145
 
            if (lua_isnil(cc, -1)) {
146
 
                if (ctx->exited) {
147
 
                    dd("run here...exiting...");
148
 
 
149
 
                    ngx_http_lua_del_thread(r, L, cc_ref, 0);
150
 
 
151
 
                    if (ctx->cleanup) {
152
 
                        *ctx->cleanup = NULL;
153
 
                        ctx->cleanup = NULL;
154
 
                    }
155
 
 
156
 
                    return ctx->exit_code;
157
 
                }
158
 
 
159
 
                if (ctx->exec_uri.len) {
160
 
                    ngx_http_lua_del_thread(r, L, cc_ref, 0);
161
 
 
162
 
                    if (ctx->cleanup) {
163
 
                        *ctx->cleanup = NULL;
164
 
                        ctx->cleanup = NULL;
165
 
                    }
166
 
 
167
 
                    if (ctx->exec_uri.data[0] == '@') {
168
 
                        if (ctx->exec_args.len > 0) {
169
 
                            ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
170
 
                                    "query strings %V ignored when exec'ing named location %V",
171
 
                                    &ctx->exec_args, &ctx->exec_uri);
172
 
                        }
173
 
 
174
 
                        return ngx_http_named_location(r, &ctx->exec_uri);
175
 
                    }
176
 
 
177
 
                    return ngx_http_internal_redirect(r, &ctx->exec_uri,
178
 
                            &ctx->exec_args);
179
 
                }
180
 
            }
181
 
 
182
 
            msg = "unknown reason";
183
 
        }
184
 
 
185
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
186
 
                "content_by_lua aborted: %s: %s",
187
 
                err, msg);
188
 
 
189
 
        ngx_http_lua_del_thread(r, L, cc_ref, 0);
190
 
 
191
 
        if (ctx->cleanup) {
192
 
            *ctx->cleanup = NULL;
193
 
            ctx->cleanup = NULL;
194
 
        }
195
 
 
196
 
        dd("headers sent? %d", ctx->headers_sent ? 1 : 0);
197
 
 
198
 
        return ctx->headers_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
199
 
    } NGX_LUA_EXCEPTION_CATCH {
200
 
        dd("NginX execution restored");
201
 
    }
202
 
 
203
 
    return NGX_ERROR;
204
 
}
205
 
 
206
 
 
 
93
void
 
94
ngx_http_lua_content_wev_handler(ngx_http_request_t *r)
 
95
{
 
96
    (void) ngx_http_lua_wev_handler(r);
 
97
}
 
98
 
 
99
 
 
100
ngx_int_t
 
101
ngx_http_lua_content_handler(ngx_http_request_t *r)
 
102
{
 
103
    ngx_http_lua_loc_conf_t     *llcf;
 
104
    ngx_http_lua_ctx_t          *ctx;
 
105
    ngx_int_t                    rc;
 
106
 
 
107
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
108
 
 
109
    if (llcf->content_handler == NULL) {
 
110
        dd("no content handler found");
 
111
        return NGX_DECLINED;
 
112
    }
 
113
 
 
114
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
115
 
 
116
    dd("ctx = %p", ctx);
 
117
 
 
118
    if (ctx == NULL) {
 
119
        ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_lua_ctx_t));
 
120
        if (ctx == NULL) {
 
121
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
122
        }
 
123
 
 
124
        dd("setting new ctx: ctx = %p", ctx);
 
125
 
 
126
        ctx->cc_ref = LUA_NOREF;
 
127
 
 
128
        ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
 
129
    }
 
130
 
 
131
    dd("entered? %d", (int) ctx->entered_content_phase);
 
132
 
 
133
    if (ctx->waiting_more_body) {
 
134
        return NGX_DONE;
 
135
    }
 
136
 
 
137
    if (ctx->entered_content_phase) {
 
138
        dd("calling wev handler");
 
139
        rc = ngx_http_lua_wev_handler(r);
 
140
        dd("wev handler returns %d", (int) rc);
 
141
        return rc;
 
142
    }
 
143
 
 
144
    if (llcf->force_read_body &&
 
145
            ! ctx->read_body_done &&
 
146
            ((r->method & NGX_HTTP_POST) || (r->method & NGX_HTTP_PUT)))
 
147
    {
 
148
        rc = ngx_http_read_client_request_body(r,
 
149
                ngx_http_lua_content_phase_post_read);
 
150
 
 
151
        if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
 
152
            return rc;
 
153
        }
 
154
 
 
155
        if (rc == NGX_AGAIN) {
 
156
            ctx->waiting_more_body = 1;
 
157
 
 
158
            return NGX_DONE;
 
159
        }
 
160
    }
 
161
 
 
162
    dd("setting entered");
 
163
 
 
164
    ctx->entered_content_phase = 1;
 
165
 
 
166
    dd("calling content handler");
 
167
    return llcf->content_handler(r);
 
168
}
 
169
 
 
170
 
 
171
/* post read callback for the content phase */
207
172
static void
208
 
ngx_http_lua_request_cleanup(void *data)
209
 
{
210
 
    ngx_http_request_t          *r = data;
211
 
    ngx_http_lua_main_conf_t    *lmcf;
212
 
    ngx_http_lua_ctx_t          *ctx;
 
173
ngx_http_lua_content_phase_post_read(ngx_http_request_t *r)
 
174
{
 
175
    ngx_http_lua_ctx_t  *ctx;
 
176
 
 
177
    r->read_event_handler = ngx_http_request_empty_handler;
 
178
 
 
179
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
180
 
 
181
    ctx->read_body_done = 1;
 
182
 
 
183
    if (ctx->waiting_more_body) {
 
184
        ctx->waiting_more_body = 0;
 
185
        ngx_http_finalize_request(r, ngx_http_lua_content_handler(r));
 
186
 
 
187
    } else {
 
188
#if defined(nginx_version) && nginx_version >= 8011
 
189
        r->main->count--;
 
190
#endif
 
191
    }
 
192
}
 
193
 
 
194
 
 
195
ngx_int_t
 
196
ngx_http_lua_content_handler_file(ngx_http_request_t *r)
 
197
{
 
198
    lua_State                       *L;
 
199
    ngx_int_t                        rc;
 
200
    u_char                          *script_path;
 
201
    ngx_http_lua_main_conf_t        *lmcf;
 
202
    ngx_http_lua_loc_conf_t         *llcf;
 
203
    char                            *err;
 
204
    ngx_str_t                        eval_src;
 
205
 
 
206
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
207
 
 
208
    if (ngx_http_complex_value(r, &llcf->content_src, &eval_src) != NGX_OK) {
 
209
        return NGX_ERROR;
 
210
    }
 
211
 
 
212
    script_path = ngx_http_lua_rebase_path(r->pool, eval_src.data,
 
213
            eval_src.len);
 
214
 
 
215
    if (script_path == NULL) {
 
216
        return NGX_ERROR;
 
217
    }
 
218
 
 
219
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
 
220
    L = lmcf->lua;
 
221
 
 
222
    /*  load Lua script file (w/ cache)        sp = 1 */
 
223
    rc = ngx_http_lua_cache_loadfile(L, script_path, llcf->content_src_key,
 
224
            &err, llcf->enable_code_cache);
 
225
 
 
226
    if (rc != NGX_OK) {
 
227
        if (err == NULL) {
 
228
            err = "unknown error";
 
229
        }
 
230
 
 
231
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
 
232
                "Failed to load Lua inlined code: %s", err);
 
233
 
 
234
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
235
    }
 
236
 
 
237
    /*  make sure we have a valid code chunk */
 
238
    assert(lua_isfunction(L, -1));
 
239
 
 
240
    rc = ngx_http_lua_content_by_chunk(L, r);
 
241
 
 
242
    if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
 
243
        return rc;
 
244
    }
 
245
 
 
246
    if (rc == NGX_DONE) {
 
247
        return NGX_DONE;
 
248
    }
 
249
 
 
250
    if (rc == NGX_AGAIN) {
 
251
#if defined(nginx_version) && nginx_version >= 8011
 
252
        r->main->count++;
 
253
#endif
 
254
        return NGX_DONE;
 
255
    }
 
256
 
 
257
    return NGX_OK;
 
258
}
 
259
 
 
260
 
 
261
ngx_int_t
 
262
ngx_http_lua_content_handler_inline(ngx_http_request_t *r)
 
263
{
213
264
    lua_State                   *L;
214
 
 
215
 
    dd("(lua-request-cleanup) force request coroutine quit");
216
 
 
217
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
218
 
    L = lmcf->lua;
219
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
220
 
 
221
 
    /*  force coroutine handling the request quit */
222
 
    if (ctx == NULL) {
223
 
        return;
224
 
    }
225
 
 
226
 
    if (ctx->cleanup) {
227
 
        *ctx->cleanup = NULL;
228
 
        ctx->cleanup = NULL;
229
 
    }
230
 
 
231
 
    lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_CORT_REF);
232
 
    lua_rawgeti(L, -1, ctx->cc_ref);
233
 
 
234
 
    if (lua_isthread(L, -1)) {
235
 
        /*  coroutine not finished yet, force quit */
236
 
        ngx_http_lua_del_thread(r, L, ctx->cc_ref, 1);
237
 
 
238
 
#if 0
239
 
        ngx_http_lua_send_chain_link(r, ctx, NULL /* indicate last_buf */);
240
 
#endif
241
 
    }
242
 
 
243
 
    lua_pop(L, 2);
244
 
}
245
 
 
246
 
 
247
 
void
248
 
ngx_http_lua_wev_handler(ngx_http_request_t *r)
249
 
{
250
265
    ngx_int_t                    rc;
251
 
    ngx_http_lua_ctx_t          *ctx;
252
266
    ngx_http_lua_main_conf_t    *lmcf;
253
 
    lua_State                   *cc;
254
 
    ngx_chain_t                 *cl;
255
 
    size_t                       len;
256
 
    u_char                      *pos, *last;
257
 
    ngx_http_headers_out_t      *sr_headers;
258
 
    ngx_list_part_t             *part;
259
 
    ngx_table_elt_t             *header;
260
 
    ngx_uint_t                   i;
261
 
 
262
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
263
 
    if (ctx == NULL) {
264
 
        goto error;
265
 
    }
266
 
 
267
 
    dd("request done: %d", (int) r->done);
268
 
    dd("cleanup done: %p", ctx->cleanup);
269
 
 
270
 
#if 1
271
 
    if (ctx->cleanup == NULL) {
272
 
        return;
273
 
    }
274
 
#endif
275
 
 
276
 
    if (ctx->waiting && ! ctx->done) {
277
 
        if (r->main->posted_requests
278
 
                && r->main->posted_requests->request != r)
279
 
        {
280
 
            dd("postpone our wev handler");
281
 
 
282
 
#if defined(nginx_version) && nginx_version >= 8012
283
 
            ngx_http_post_request(r, NULL);
284
 
#else
285
 
            ngx_http_post_request(r);
286
 
#endif
287
 
 
288
 
            return;
289
 
        }
290
 
    }
291
 
 
292
 
    ctx->done = 0;
293
 
 
294
 
    len = 0;
295
 
    for (cl = ctx->sr_body; cl; cl = cl->next) {
296
 
        /*  ignore all non-memory buffers */
297
 
        len += cl->buf->last - cl->buf->pos;
298
 
    }
299
 
 
300
 
    if (len == 0) {
301
 
        pos = NULL;
302
 
 
303
 
    } else {
304
 
        last = pos = ngx_palloc(r->pool, len);
305
 
        if (pos == NULL) {
306
 
            goto error;
307
 
        }
308
 
 
309
 
        for (cl = ctx->sr_body; cl; cl = cl->next) {
310
 
            /*  ignore all non-memory buffers */
311
 
            last = ngx_copy(last, cl->buf->pos, cl->buf->last - cl->buf->pos);
312
 
        }
313
 
    }
314
 
 
315
 
    cc = ctx->cc;
316
 
 
317
 
    /*  {{{ construct ret value */
318
 
    lua_newtable(cc);
319
 
 
320
 
    /*  copy captured status */
321
 
    lua_pushinteger(cc, ctx->sr_status);
322
 
    lua_setfield(cc, -2, "status");
323
 
 
324
 
    /*  copy captured body */
325
 
    lua_pushlstring(cc, (const char *) pos, len);
326
 
    lua_setfield(cc, -2, "body");
327
 
 
328
 
    /* copy captured headers */
329
 
 
330
 
    lua_newtable(cc); /* res.header */
331
 
 
332
 
    sr_headers = ctx->sr_headers;
333
 
 
334
 
    if (sr_headers->content_length == NULL
335
 
        && sr_headers->content_length_n >= 0)
336
 
    {
337
 
        lua_pushliteral(cc, "Content-Length"); /* header key */
338
 
        lua_pushnumber(cc, sr_headers->content_length_n); /* head key value */
339
 
        lua_rawset(cc, -3); /* head */
340
 
    }
341
 
 
342
 
    if (sr_headers->content_type.len) {
343
 
        lua_pushliteral(cc, "Content-Type"); /* header key */
344
 
        lua_pushlstring(cc, (char *) sr_headers->content_type.data,
345
 
                sr_headers->content_type.len); /* head key value */
346
 
        lua_rawset(cc, -3); /* head */
347
 
    }
348
 
 
349
 
    part = &sr_headers->headers.part;
350
 
    header = part->elts;
351
 
 
352
 
    for (i = 0; /* void */; i++) {
353
 
 
354
 
        if (i >= part->nelts) {
355
 
            if (part->next == NULL) {
356
 
                break;
357
 
            }
358
 
 
359
 
            part = part->next;
360
 
            header = part->elts;
361
 
            i = 0;
362
 
        }
363
 
 
364
 
#if 1
365
 
        if (header[i].hash == 0) {
366
 
            continue;
367
 
        }
368
 
#endif
369
 
 
370
 
        lua_pushlstring(cc, (char *) header[i].key.data,
371
 
                header[i].key.len); /* header key */
372
 
 
373
 
        lua_pushlstring(cc, (char *) header[i].value.data,
374
 
                header[i].value.len); /* header key value */
375
 
 
376
 
        lua_rawset(cc, -3); /* head */
377
 
    }
378
 
 
379
 
    lua_setfield(cc, -2, "header");
380
 
 
381
 
    /*  }}} */
382
 
 
 
267
    ngx_http_lua_loc_conf_t     *llcf;
 
268
    char                        *err;
 
269
 
 
270
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
383
271
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
384
272
 
385
 
    dd("about to run thread...");
386
 
 
387
 
    rc = ngx_http_lua_run_thread(lmcf->lua, r, ctx, 1);
388
 
 
389
 
    dd("already run thread...");
390
 
 
391
 
    if (rc == NGX_AGAIN || rc == NGX_DONE) {
392
 
        ctx->waiting = 1;
393
 
        ctx->done = 0;
394
 
 
395
 
    } else {
396
 
        ctx->waiting = 0;
397
 
        ctx->done = 1;
398
 
 
399
 
        ngx_http_finalize_request(r, rc);
400
 
    }
401
 
 
402
 
    return;
403
 
 
404
 
error:
405
 
    ngx_http_finalize_request(r,
406
 
            ctx->headers_sent ? NGX_ERROR: NGX_HTTP_INTERNAL_SERVER_ERROR);
407
 
 
408
 
    return;
 
273
    L = lmcf->lua;
 
274
 
 
275
    /*  load Lua inline script (w/ cache) sp = 1 */
 
276
    rc = ngx_http_lua_cache_loadbuffer(L, llcf->content_src.value.data,
 
277
            llcf->content_src.value.len, llcf->content_src_key,
 
278
            "content_by_lua", &err, llcf->enable_code_cache);
 
279
 
 
280
    if (rc != NGX_OK) {
 
281
        if (err == NULL) {
 
282
            err = "unknown error";
 
283
        }
 
284
 
 
285
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
 
286
                "Failed to load Lua inlined code: %s", err);
 
287
 
 
288
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
289
    }
 
290
 
 
291
    rc = ngx_http_lua_content_by_chunk(L, r);
 
292
 
 
293
    if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
 
294
        return rc;
 
295
    }
 
296
 
 
297
    if (rc == NGX_DONE) {
 
298
        return NGX_DONE;
 
299
    }
 
300
 
 
301
    if (rc == NGX_AGAIN) {
 
302
#if defined(nginx_version) && nginx_version >= 8011
 
303
        r->main->count++;
 
304
#endif
 
305
        return NGX_DONE;
 
306
    }
 
307
 
 
308
    return NGX_OK;
409
309
}
410
310