static ngx_int_t __init_request(const ngx_http_fetch_args_t * args, ngx_http_request_t *r) { r->method = args->http_method; r->http_version = NGX_HTTP_VERSION_11; // r->request_line; if (NGX_OK != ngx_http_fetch_copy_str(&args->uri, r->pool, &r->uri)) { return NGX_ERROR; } if (args->args.data && args->args.len > 0) { if (NGX_OK != ngx_http_fetch_copy_str(&args->args, r->pool, &r->args)) { return NGX_ERROR; } } else { r->args.data = 0; r->args.len = 0; } r->header_hash = 1; r->subrequest_in_memory = 1; // r->keepalive = !!args->keepalive; r->method_name = ngx_http_fetch_get_method(args->http_method); // r->http_protocol ngx_http_set_exten(r); ngx_time_t *tp = ngx_timeofday(); r->start_sec = tp->sec; r->start_msec = tp->msec; return NGX_OK; }
static int ngx_http_lua_ngx_req_set_uri(lua_State *L) { ngx_http_request_t *r; size_t len; u_char *p; int n; int jump = 0; ngx_http_lua_ctx_t *ctx; n = lua_gettop(L); if (n != 1 && n != 2) { return luaL_error(L, "expecting 1 argument but seen %d", n); } lua_pushlightuserdata(L, &ngx_http_lua_request_key); lua_rawget(L, LUA_GLOBALSINDEX); r = lua_touserdata(L, -1); lua_pop(L, 1); if (n == 2) { luaL_checktype(L, 2, LUA_TBOOLEAN); jump = lua_toboolean(L, 2); if (jump) { ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module); if (ctx == NULL) { return luaL_error(L, "no ctx found"); } dd("rewrite: %d, access: %d, content: %d", (int) ctx->entered_rewrite_phase, (int) ctx->entered_access_phase, (int) ctx->entered_content_phase); ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "lua set uri jump to \"%V\"", &r->uri); ngx_http_lua_check_if_abortable(L, ctx); } } p = (u_char *) luaL_checklstring(L, 1, &len); if (len == 0) { return luaL_error(L, "attempt to use zero-length uri"); } r->uri.data = ngx_palloc(r->pool, len); if (r->uri.data == NULL) { return luaL_error(L, "out of memory"); } ngx_memcpy(r->uri.data, p, len); r->uri.len = len; r->internal = 1; r->valid_unparsed_uri = 0; ngx_http_set_exten(r); if (jump) { r->uri_changed = 1; return lua_yield(L, 0); } r->valid_location = 0; r->uri_changed = 0; return 0; }