[lua]: add subrequests

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent 10ea96230b
commit 77ad119f66
  1. 5
      include/lighttpd/core_lua.h
  2. 2
      include/lighttpd/request.h
  3. 2
      include/lighttpd/virtualrequest.h
  4. 1
      src/CMakeLists.txt
  5. 1
      src/main/Makefile.am
  6. 2
      src/main/actions.c
  7. 10
      src/main/actions_lua.c
  8. 2
      src/main/connection.c
  9. 27
      src/main/request.c
  10. 9
      src/main/virtualrequest.c
  11. 2
      src/main/virtualrequest_lua.c
  12. 1
      src/main/worker.c
  13. 1
      src/main/wscript

@ -51,6 +51,8 @@ LI_API void li_lua_init_stat_mt(lua_State *L);
LI_API struct stat* li_lua_get_stat(lua_State *L, int ndx);
LI_API int li_lua_push_stat(lua_State *L, struct stat *st);
LI_API void li_lua_init_subrequest_mt(lua_State *L);
LI_API void li_lua_init_vrequest_mt(lua_State *L);
LI_API liVRequest* li_lua_get_vrequest(lua_State *L, int ndx);
LI_API int li_lua_push_vrequest(lua_State *L, liVRequest *vr);
@ -95,4 +97,7 @@ LI_API GString* li_lua_print_get_string(lua_State *L, int from, int to);
*/
LI_API int li_lua_ghashtable_gstring_pairs(lua_State *L, GHashTable *ht);
/* internal: subrequests (vrequest metamethod) */
LI_API int li_lua_vrequest_subrequest(lua_State *L);
#endif

@ -39,6 +39,8 @@ LI_API void li_request_init(liRequest *req);
LI_API void li_request_reset(liRequest *req);
LI_API void li_request_clear(liRequest *req);
LI_API void li_request_copy(liRequest *dest, const liRequest *src);
LI_API gboolean li_request_validate_header(liConnection *con);
LI_API void li_physical_init(liPhysical *phys);

@ -160,7 +160,7 @@ struct liVRequest {
} \
} while (0)
LI_API liVRequest* li_vrequest_new(liConnection *con, liConInfo *coninfo);
LI_API liVRequest* li_vrequest_new(liWorker *wrk, liConInfo *coninfo);
LI_API void li_vrequest_free(liVRequest *vr);
/* if keepalive = TRUE, you either have to reset it later again with FALSE or call li_vrequest_start before reusing the vr;
* keepalive = TRUE doesn't reset the vr->request fields, so mod_status can show the last request data in the keep-alive state

@ -254,6 +254,7 @@ SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC}
request_lua.c
response_lua.c
stat_lua.c
subrequest_lua.c
virtualrequest_lua.c
)
ENDIF(WITH_LUA)

@ -57,6 +57,7 @@ lua_src= \
request_lua.c \
response_lua.c \
stat_lua.c \
subrequest_lua.c \
virtualrequest_lua.c

@ -178,6 +178,8 @@ static void li_action_backend_stack_reset(liVRequest *vr, liActionStack *as) {
liServer *srv = vr->wrk->srv;
guint i;
if (NULL == as->backend_stack) return;
/* index 0 is the "deepest" backend - release it first */
for (i = 0; i < as->backend_stack->len; i++ ) {
action_stack_element_release(srv, vr, &g_array_index(as->backend_stack, action_stack_element, i));

@ -1,5 +1,6 @@
#include <lighttpd/actions_lua.h>
#include <lighttpd/config_lua.h>
#include <lighttpd/core_lua.h>
#include <lualib.h>
@ -147,6 +148,11 @@ static void lua_action_free(liServer *srv, gpointer param) {
liAction* li_lua_make_action(lua_State *L, int ndx) {
lua_action_param *par = g_slice_new0(lua_action_param);
liWorker *wrk;
lua_getfield(L, LUA_REGISTRYINDEX, "lighty.wrk");
wrk = lua_touserdata(L, -1);
lua_pop(L, 1);
lua_pushvalue(L, ndx); /* +1 */
par->func_ref = luaL_ref(L, LUA_REGISTRYINDEX); /* -1 */
@ -160,6 +166,10 @@ liAction* li_lua_make_action(lua_State *L, int ndx) {
lua_getfield(L, LUA_REGISTRYINDEX, "li_globals"); /* +1 */
lua_setfield(L, -2, "__index"); /* -1 */
lua_setmetatable(L, -2); /* -1 */
if (NULL != wrk) {
li_lua_config_publish_str_hash(wrk->srv, wrk, L, wrk->srv->actions, li_lua_config_handle_server_action); /* +1 */
lua_setfield(L, -2, "action"); /* -1 */
}
lua_setfenv(L, -2); /* -1 */
lua_pop(L, 1); /* -1 */

@ -530,7 +530,7 @@ liConnection* li_connection_new(liWorker *wrk) {
con->info.callbacks = &con_callbacks;
con->mainvr = li_vrequest_new(con, &con->info);
con->mainvr = li_vrequest_new(wrk, &con->info);
li_http_request_parser_init(&con->req_parser_ctx, &con->mainvr->request, con->raw_in);
con->in = con->mainvr->vr_in;

@ -59,6 +59,33 @@ void li_request_clear(liRequest *req) {
req->content_length = -1;
}
void li_request_copy(liRequest *dest, const liRequest *src) {
GList *iter;
dest->http_method = src->http_method;
li_string_assign_len(dest->http_method_str, GSTR_LEN(src->http_method_str));
dest->http_version = src->http_version;
li_string_assign_len(dest->uri.raw, GSTR_LEN(src->uri.raw));
li_string_assign_len(dest->uri.raw_path, GSTR_LEN(src->uri.raw_path));
li_string_assign_len(dest->uri.raw_orig_path, GSTR_LEN(src->uri.raw_orig_path));
li_string_assign_len(dest->uri.scheme, GSTR_LEN(src->uri.scheme));
li_string_assign_len(dest->uri.authority, GSTR_LEN(src->uri.authority));
li_string_assign_len(dest->uri.path, GSTR_LEN(src->uri.path));
li_string_assign_len(dest->uri.query, GSTR_LEN(src->uri.query));
li_string_assign_len(dest->uri.host, GSTR_LEN(src->uri.host));
li_http_headers_reset(dest->headers);
for (iter = g_queue_peek_head_link(&src->headers->entries); iter; iter = g_list_next(iter)) {
liHttpHeader* header = (liHttpHeader*) iter->data;
li_http_header_insert(dest->headers, LI_HEADER_KEY_LEN(header), LI_HEADER_VALUE_LEN(header));
}
dest->content_length = src->content_length;
}
/* closes connection after response */
static void bad_request(liConnection *con, int status) {
con->info.keep_alive = FALSE;

@ -136,16 +136,16 @@ liFilter* li_vrequest_add_filter_out(liVRequest *vr, liFilterHandlerCB handle_da
return filters_add(&vr->filters_out, handle_data, handle_free, param);
}
liVRequest* li_vrequest_new(liConnection *con, liConInfo *coninfo) {
liServer *srv = con->srv;
liVRequest* li_vrequest_new(liWorker *wrk, liConInfo *coninfo) {
liServer *srv = wrk->srv;
liVRequest *vr = g_slice_new0(liVRequest);
vr->coninfo = coninfo;
vr->wrk = con->wrk;
vr->wrk = wrk;
vr->ref = g_slice_new0(liVRequestRef);
vr->ref->refcount = 1;
vr->ref->vr = vr;
vr->ref->wrk = con->wrk;
vr->ref->wrk = wrk;
vr->state = LI_VRS_CLEAN;
vr->plugin_ctx = g_ptr_array_new();
@ -656,6 +656,7 @@ void li_vrequest_joblist_append(liVRequest *vr) {
void li_vrequest_joblist_append_async(liVRequestRef *vr_ref) {
liWorker *wrk = vr_ref->wrk;
GAsyncQueue *const q = wrk->job_async_queue;
if (NULL == q) return;
li_vrequest_ref_acquire(vr_ref);
g_async_queue_push(q, vr_ref);
ev_async_send(wrk->loop, &wrk->job_async_queue_watcher);

@ -335,6 +335,8 @@ static const luaL_Reg vrequest_mt[] = {
{ "add_filter_in", lua_vrequest_add_filter_in },
{ "add_filter_out", lua_vrequest_add_filter_out },
{ "subrequest", li_lua_vrequest_subrequest },
{ NULL, NULL }
};

@ -524,6 +524,7 @@ void li_worker_free(liWorker *wrk) {
}
g_async_queue_unref(q);
wrk->job_async_queue = NULL;
}

@ -81,6 +81,7 @@ def build(bld):
request_lua.c
response_lua.c
stat_lua.c
subrequest_lua.c
virtualrequest_lua.c
'''

Loading…
Cancel
Save