Skip to content

Commit

Permalink
HTTP: Refactored static action
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhidao committed Apr 10, 2024
1 parent 26b8daa commit c6e1d97
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/nxt_http_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static nxt_http_action_t *nxt_http_static(nxt_task_t *task,
nxt_http_request_t *r, nxt_http_action_t *action);
static void nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_static_ctx_t *ctx);
static void nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data);
static void nxt_http_static_send_error(nxt_task_t *task, void *obj, void *data);
static void nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_static_ctx_t *ctx);
static void nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_static_ctx_t *ctx, nxt_http_status_t status);
#if (NXT_HAVE_OPENAT2)
Expand Down Expand Up @@ -271,35 +271,44 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
}
#endif

nxt_http_static_send_ready(task, r, ctx);

} else {
rtcf = r->conf->socket_conf->router_conf;

ret = nxt_tstr_query_init(&r->tstr_query, rtcf->tstr_state,
&r->tstr_cache, r, r->mem_pool);
if (nxt_slow_path(ret != NXT_OK)) {
nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
return;
goto fail;
}

nxt_tstr_query(task, r->tstr_query, share->tstr, &ctx->share);
ret = nxt_tstr_query(task, r->tstr_query, share->tstr, &ctx->share);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}

#if (NXT_HAVE_OPENAT2)
if (conf->chroot != NULL && ctx->share_idx == 0) {
nxt_tstr_query(task, r->tstr_query, conf->chroot, &ctx->chroot);
ret = nxt_tstr_query(task, r->tstr_query, conf->chroot,
&ctx->chroot);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
}
#endif
}

nxt_http_static_send(task, r, ctx);

return;

fail:

nxt_tstr_query_resolve(task, r->tstr_query, ctx,
nxt_http_static_send_ready,
nxt_http_static_send_error);
}
nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
}


static void
nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_static_ctx_t *ctx)
{
size_t length, encode;
u_char *p, *fname;
Expand All @@ -314,13 +323,9 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
nxt_http_status_t status;
nxt_router_conf_t *rtcf;
nxt_http_action_t *action;
nxt_http_request_t *r;
nxt_work_handler_t body_handler;
nxt_http_static_ctx_t *ctx;
nxt_http_static_conf_t *conf;

r = obj;
ctx = data;
action = ctx->action;
conf = action->u.conf;
rtcf = r->conf->socket_conf->router_conf;
Expand Down Expand Up @@ -662,17 +667,6 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
}


static void
nxt_http_static_send_error(nxt_task_t *task, void *obj, void *data)
{
nxt_http_request_t *r;

r = obj;

nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
}


static void
nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_static_ctx_t *ctx, nxt_http_status_t status)
Expand Down

0 comments on commit c6e1d97

Please sign in to comment.