summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_controller.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2017-05-18 20:40:19 +0300
committerValentin Bartenev <vbart@nginx.com>2017-05-18 20:40:19 +0300
commitc7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d (patch)
tree97cbf3d6a4ced6b0ab14e5336292d97178bf78b4 /src/nxt_controller.c
parentdc95b2f3de76df03b64bab9bbc5e6a9dc7015550 (diff)
downloadunit-c7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d.tar.gz
unit-c7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d.tar.bz2
Controller: partial retrieving of configuration.
Diffstat (limited to '')
-rw-r--r--src/nxt_controller.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/nxt_controller.c b/src/nxt_controller.c
index f02b1747..f70b481c 100644
--- a/src/nxt_controller.c
+++ b/src/nxt_controller.c
@@ -554,13 +554,34 @@ static void
nxt_controller_process_request(nxt_task_t *task, nxt_event_conn_t *c,
nxt_controller_request_t *req)
{
+ nxt_str_t path;
+ nxt_conf_json_value_t *value;
nxt_controller_response_t resp;
nxt_memzero(&resp, sizeof(nxt_controller_response_t));
if (nxt_str_eq(&req->parser.method, "GET", 3)) {
- nxt_str_set(&resp.status_line, "200 OK");
- resp.json_value = nxt_controller_conf.root;
+
+ path.start = req->parser.target_start;
+
+ if (req->parser.args_start != NULL) {
+ path.length = req->parser.args_start - path.start;
+
+ } else {
+ path.length = req->parser.target_end - path.start;
+ }
+
+ value = nxt_conf_json_value_get(nxt_controller_conf.root, &path);
+
+ if (value != NULL) {
+ nxt_str_set(&resp.status_line, "200 OK");
+ resp.json_value = value;
+
+ } else {
+ nxt_str_set(&resp.status_line, "404 Not Found");
+ nxt_str_set(&resp.json_string,
+ "{ \"error\": \"Requested value doesn't exist\" }");
+ }
} else if (nxt_str_eq(&req->parser.method, "PUT", 3)) {