Added support for a default root object (fix #26)

master
Nicolas Favre-Felix 13 years ago
parent 712d7b061d
commit 94fb611bf3

@ -39,6 +39,7 @@ curl -d "GET/hello" http://127.0.0.1:7379/
* File upload with PUT. * File upload with PUT.
* With the JSON output, the return value of INFO is parsed and transformed into an object. * With the JSON output, the return value of INFO is parsed and transformed into an object.
* Optional daemonize. * 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... # Ideas, TODO...
* Add better support for PUT, DELETE, HEAD, OPTIONS? How? For which commands? * Add better support for PUT, DELETE, HEAD, OPTIONS? How? For which commands?

@ -5,6 +5,7 @@
#include "worker.h" #include "worker.h"
#include "websocket.h" #include "websocket.h"
#include "cmd.h" #include "cmd.h"
#include "conf.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -183,6 +184,15 @@ http_client_on_message_complete(struct http_parser *p) {
c->is_websocket = 1; c->is_websocket = 1;
return 0; 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); worker_process_client(c);
http_client_reset(c); http_client_reset(c);

@ -87,6 +87,8 @@ conf_read(const char *filename) {
conf->database = json_integer_value(jtmp); conf->database = json_integer_value(jtmp);
} else if(strcmp(json_object_iter_key(kv), "pool_size") == 0 && json_typeof(jtmp) == JSON_INTEGER) { } 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); 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));
} }
} }

@ -35,6 +35,9 @@ struct conf {
/* Logging */ /* Logging */
char *logfile; char *logfile;
log_level verbosity; log_level verbosity;
/* Request to serve on “/” */
char *default_root;
}; };
struct conf * struct conf *

Loading…
Cancel
Save