~spuul/nginx/trunk

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-02-15 03:05:42 UTC
  • mfrom: (4.3.10 sid)
  • Revision ID: package-import@ubuntu.com-20140215030542-71ubtowl24vf7nfn
Tags: 1.4.5-1ubuntu1
* Resynchronise with Debian (LP: #1280511).  Remaining changes:
  - debian/patches/ubuntu-branding.patch:
    + Add Ubuntu branding to server_tokens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
                          n);
70
70
    }
71
71
 
72
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
73
 
    lua_rawget(L, LUA_GLOBALSINDEX);
74
 
    r = lua_touserdata(L, -1);
75
 
    lua_pop(L, 1);
76
 
 
 
72
    r = ngx_http_lua_get_req(L);
77
73
    if (r == NULL) {
78
74
        return luaL_error(L, "no request object found");
79
75
    }
112
108
    if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags)
113
109
        != NGX_OK)
114
110
    {
115
 
        ctx->headers_sent = 1;
116
111
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
117
112
    }
118
113
 
177
172
        }
178
173
    }
179
174
 
180
 
    if (ctx->headers_sent) {
 
175
    if (r->header_sent) {
181
176
        return luaL_error(L, "attempt to call ngx.exec after "
182
177
                          "sending out response headers");
183
178
    }
225
220
        rc = NGX_HTTP_MOVED_TEMPORARILY;
226
221
    }
227
222
 
228
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
229
 
    lua_rawget(L, LUA_GLOBALSINDEX);
230
 
    r = lua_touserdata(L, -1);
231
 
    lua_pop(L, 1);
232
 
 
 
223
    r = ngx_http_lua_get_req(L);
233
224
    if (r == NULL) {
234
225
        return luaL_error(L, "no request object found");
235
226
    }
245
236
 
246
237
    ngx_http_lua_check_if_abortable(L, ctx);
247
238
 
248
 
    if (ctx->headers_sent) {
 
239
    if (r->header_sent) {
249
240
        return luaL_error(L, "attempt to call ngx.redirect after sending out "
250
241
                          "the headers");
251
242
    }
262
253
        return luaL_error(L, "out of memory");
263
254
    }
264
255
 
265
 
    r->headers_out.location->hash =
266
 
            ngx_hash(ngx_hash(ngx_hash(ngx_hash(ngx_hash(ngx_hash(
267
 
                     ngx_hash('l', 'o'), 'c'), 'a'), 't'), 'i'), 'o'), 'n');
 
256
    r->headers_out.location->hash = ngx_http_lua_location_hash;
268
257
 
269
258
#if 0
270
259
    dd("location hash: %lu == %lu",
301
290
        return luaL_error(L, "expecting one argument");
302
291
    }
303
292
 
304
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
305
 
    lua_rawget(L, LUA_GLOBALSINDEX);
306
 
    r = lua_touserdata(L, -1);
307
 
    lua_pop(L, 1);
308
 
 
 
293
    r = ngx_http_lua_get_req(L);
309
294
    if (r == NULL) {
310
295
        return luaL_error(L, "no request object found");
311
296
    }
318
303
    ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
319
304
                               | NGX_HTTP_LUA_CONTEXT_ACCESS
320
305
                               | NGX_HTTP_LUA_CONTEXT_CONTENT
321
 
                               | NGX_HTTP_LUA_CONTEXT_TIMER);
 
306
                               | NGX_HTTP_LUA_CONTEXT_TIMER
 
307
                               | NGX_HTTP_LUA_CONTEXT_HEADER_FILTER);
322
308
 
323
309
    rc = (ngx_int_t) luaL_checkinteger(L, 1);
324
310
 
331
317
        return luaL_error(L, "attempt to abort with pending subrequests");
332
318
    }
333
319
 
334
 
    if (ctx->headers_sent
 
320
    if (r->header_sent
335
321
        && rc >= NGX_HTTP_SPECIAL_RESPONSE
336
322
        && rc != NGX_HTTP_REQUEST_TIME_OUT
337
323
        && rc != NGX_HTTP_CLIENT_CLOSED_REQUEST
346
332
        rc = NGX_HTTP_OK;
347
333
    }
348
334
 
 
335
    dd("setting exit code: %d", (int) rc);
 
336
 
349
337
    ctx->exit_code = rc;
350
338
    ctx->exited = 1;
351
339
 
352
340
    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
353
341
                   "lua exit with code %i", ctx->exit_code);
354
342
 
 
343
    if (ctx->context & NGX_HTTP_LUA_CONTEXT_HEADER_FILTER) {
 
344
        return 0;
 
345
    }
 
346
 
355
347
    dd("calling yield");
356
348
    return lua_yield(L, 0);
357
349
}
365
357
    ngx_http_lua_co_ctx_t        *coctx = NULL;
366
358
    ngx_http_lua_loc_conf_t      *llcf;
367
359
 
368
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
369
 
    lua_rawget(L, LUA_GLOBALSINDEX);
370
 
    r = lua_touserdata(L, -1);
371
 
    lua_pop(L, 1);
372
 
 
 
360
    r = ngx_http_lua_get_req(L);
373
361
    if (r == NULL) {
374
362
        return luaL_error(L, "no request found");
375
363
    }
417
405
    return 1;
418
406
}
419
407
 
 
408
 
 
409
#ifndef NGX_HTTP_LUA_NO_FFI_API
 
410
int
 
411
ngx_http_lua_ffi_exit(ngx_http_request_t *r, int status, u_char *err,
 
412
    size_t *errlen)
 
413
{
 
414
    ngx_http_lua_ctx_t       *ctx;
 
415
 
 
416
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
417
    if (ctx == NULL) {
 
418
        *errlen = ngx_snprintf(err, *errlen, "no request ctx found") - err;
 
419
        return NGX_ERROR;
 
420
    }
 
421
 
 
422
    if (ngx_http_lua_ffi_check_context(ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
 
423
                                       | NGX_HTTP_LUA_CONTEXT_ACCESS
 
424
                                       | NGX_HTTP_LUA_CONTEXT_CONTENT
 
425
                                       | NGX_HTTP_LUA_CONTEXT_TIMER
 
426
                                       | NGX_HTTP_LUA_CONTEXT_HEADER_FILTER,
 
427
                                       err, errlen)
 
428
        != NGX_OK)
 
429
    {
 
430
        return NGX_ERROR;
 
431
    }
 
432
 
 
433
    if (ctx->no_abort
 
434
        && status != NGX_ERROR
 
435
        && status != NGX_HTTP_CLOSE
 
436
        && status != NGX_HTTP_REQUEST_TIME_OUT
 
437
        && status != NGX_HTTP_CLIENT_CLOSED_REQUEST)
 
438
    {
 
439
        *errlen = ngx_snprintf(err, *errlen,
 
440
                               "attempt to abort with pending subrequests")
 
441
                  - err;
 
442
        return NGX_ERROR;
 
443
    }
 
444
 
 
445
    if (r->header_sent
 
446
        && status >= NGX_HTTP_SPECIAL_RESPONSE
 
447
        && status != NGX_HTTP_REQUEST_TIME_OUT
 
448
        && status != NGX_HTTP_CLIENT_CLOSED_REQUEST
 
449
        && status != NGX_HTTP_CLOSE)
 
450
    {
 
451
        if (status != (ngx_int_t) r->headers_out.status) {
 
452
            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "attempt to "
 
453
                          "set status %i via ngx.exit after sending out the "
 
454
                          "response status %ui", status,
 
455
                          r->headers_out.status);
 
456
        }
 
457
 
 
458
        status = NGX_HTTP_OK;
 
459
    }
 
460
 
 
461
    ctx->exit_code = status;
 
462
    ctx->exited = 1;
 
463
 
 
464
    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
465
                   "lua exit with code %i", ctx->exit_code);
 
466
 
 
467
    if (ctx->context & NGX_HTTP_LUA_CONTEXT_HEADER_FILTER) {
 
468
        return NGX_DONE;
 
469
    }
 
470
 
 
471
    return NGX_OK;
 
472
}
 
473
#endif  /* NGX_HTTP_LUA_NO_FFI_API */
 
474
 
420
475
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */