summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2024-04-18 18:29:15 +0800
committerZhidao HONG <z.hong@f5.com>2024-08-20 09:17:23 +0800
commit9d19e7e0ff5cfd75644df9fcf91c37db25aa7109 (patch)
treedc5a2d3d40f4157e4ba5d9e2217c12a6d8346551
parent08a23272a7b8618400a4de725bccd1d016329c9a (diff)
downloadunit-9d19e7e0ff5cfd75644df9fcf91c37db25aa7109.tar.gz
unit-9d19e7e0ff5cfd75644df9fcf91c37db25aa7109.tar.bz2
http: Refactor static action
-rw-r--r--src/nxt_http_static.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index ee25015e..67591595 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -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)
@@ -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;
@@ -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;
@@ -663,17 +668,6 @@ fail:
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)
{