int noit_rest_request_dispatcher(noit_http_session_ctx *ctx) { noit_http_rest_closure_t *restc = noit_http_session_dispatcher_closure(ctx); rest_request_handler handler = restc->fastpath; if(!handler) handler = noit_http_get_handler(restc); if(handler) { void *old_closure = restc, *new_closure; noit_http_response *res = noit_http_session_response(ctx); int rv; rv = handler(restc, restc->nparams, restc->params); /* If the request is closed, we need to cleanup. However * if the dispatch closure has changed, the callee has done * something (presumably freeing the restc in the process) * and it would be unsafe for us to free it as well. */ new_closure = noit_http_session_dispatcher_closure(ctx); if(old_closure == new_closure && noit_http_response_closed(res)) noit_http_rest_clean_request(restc); return rv; } noit_http_response_status_set(ctx, 404, "NOT FOUND"); noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED); noit_http_rest_clean_request(restc); noit_http_response_end(ctx); return 0; }
static int rest_test_check_err(noit_http_rest_closure_t *restc, int npats, char **pats) { noit_http_response *res = noit_http_session_response(restc->http_ctx); noit_skiplist_remove(&in_progress, restc, (noit_freefunc_t)rest_test_check_result); if(noit_http_response_complete(res) != noit_true) { noit_http_response_standard(restc->http_ctx, 500, "ERROR", "text/html"); noit_http_response_end(restc->http_ctx); } return 0; }