From 94fb611bf3ceaf6260a8bfc69f7ec972605fc4e4 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Jun 2011 22:11:29 +0200 Subject: [PATCH] Added support for a default root object (fix #26) --- README.markdown | 1 + client.c | 10 ++++++++++ conf.c | 2 ++ conf.h | 3 +++ 4 files changed, 16 insertions(+) diff --git a/README.markdown b/README.markdown index b8f237d..3ed4081 100644 --- a/README.markdown +++ b/README.markdown @@ -39,6 +39,7 @@ curl -d "GET/hello" http://127.0.0.1:7379/ * File upload with PUT. * With the JSON output, the return value of INFO is parsed and transformed into an object. * Optional daemonize. +* Default root object: Add `"default_root": "/GET/index.html"` in webdis.json to substitute the request to `/` with a Redis request. # Ideas, TODO... * Add better support for PUT, DELETE, HEAD, OPTIONS? How? For which commands? diff --git a/client.c b/client.c index 8eecde2..7d4e32a 100644 --- a/client.c +++ b/client.c @@ -5,6 +5,7 @@ #include "worker.h" #include "websocket.h" #include "cmd.h" +#include "conf.h" #include #include @@ -183,6 +184,15 @@ http_client_on_message_complete(struct http_parser *p) { c->is_websocket = 1; return 0; } + + /* handle default root object */ + if(c->path_sz == 1 && *c->path == '/' && c->w->s->cfg->default_root) { /* replace */ + free(c->path); + c->path = strdup(c->w->s->cfg->default_root); + c->path_sz = strlen(c->path); + } + + worker_process_client(c); http_client_reset(c); diff --git a/conf.c b/conf.c index c234953..30d43f6 100644 --- a/conf.c +++ b/conf.c @@ -87,6 +87,8 @@ conf_read(const char *filename) { conf->database = json_integer_value(jtmp); } else if(strcmp(json_object_iter_key(kv), "pool_size") == 0 && json_typeof(jtmp) == JSON_INTEGER) { conf->pool_size_per_thread = json_integer_value(jtmp); + } else if(strcmp(json_object_iter_key(kv), "default_root") == 0 && json_typeof(jtmp) == JSON_STRING) { + conf->default_root = strdup(json_string_value(jtmp)); } } diff --git a/conf.h b/conf.h index 385149b..af06bb5 100644 --- a/conf.h +++ b/conf.h @@ -35,6 +35,9 @@ struct conf { /* Logging */ char *logfile; log_level verbosity; + + /* Request to serve on “/” */ + char *default_root; }; struct conf *