Started adding support for a custom content-type in a second key.

master
Nicolas Favre-Felix 14 years ago
parent f931f18971
commit 1ad059d7b9

@ -1,7 +1,7 @@
OUT=webdis
HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o hiredis/dict.o
JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o
FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o
FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o formats/custom-type.o
OBJS=webdis.o conf.o $(FORMAT_OBJS) cmd.o server.o $(HIREDIS_OBJ) $(JANSSON_OBJ) libb64/cencode.o acl.o
CFLAGS=-O3 -Wall -Wextra -I. -Ijansson/src
LDFLAGS=-levent

@ -25,9 +25,9 @@ curl -d "GET/hello" http://127.0.0.1:7379/
* Possible Redis authentication in the config file.
* Pub/Sub using `Transfer-Encoding: chunked`, works with JSONP as well. Webdis can be used as a Comet server.
* Drop privileges on startup.
* MIME type in a second key with `?format=custom&typeKey=`
# Ideas, TODO...
* Add meta-data info per key (MIME type in a second key, for instance).
* Support PUT, DELETE, HEAD, OPTIONS? How? For which commands?
* MULTI/EXEC/DISCARD/WATCH are disabled at the moment; find a way to use them.
* Add logs.

@ -5,6 +5,7 @@
#include "formats/json.h"
#include "formats/raw.h"
#include "formats/custom-type.h"
#include <stdlib.h>
#include <string.h>
@ -134,6 +135,9 @@ cmd_run(struct server *s, struct evhttp_request *rq,
cur_param++;
}
/* MGET if */
// if(cmd->arg_len[0] == 3 && strncasecmp(cmd->argv[0], "GET", 3) == 0 && ) {
redisAsyncCommandArgv(s->ac, fun, cmd, param_count, cmd->argv, cmd->argv_len);
return 0;
}
@ -152,6 +156,8 @@ get_formatting_function(struct evkeyvalq *params) {
return raw_reply;
} else if(strcmp(kv->value, "json") == 0) {
return json_reply;
} else if(strcmp(kv->value, "custom") == 0) {
return custom_type_reply;
}
break;
}

@ -0,0 +1,44 @@
#include "custom-type.h"
#include "cmd.h"
#include "common.h"
#include <string.h>
#include <hiredis/hiredis.h>
#include <hiredis/async.h>
void
custom_type_reply(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
struct cmd *cmd = privdata;
char *ct;
(void)c;
evhttp_clear_headers(&cmd->uri_params);
if (reply == NULL) {
evhttp_send_reply(cmd->rq, 404, "Not Found", NULL);
return;
}
/* we expect array(string, string) */
if(reply->type != REDIS_REPLY_ARRAY || reply->elements != 2) {
evhttp_send_reply(cmd->rq, 400, "Bad request", NULL);
return;
}
if(reply->element[0]->type != REDIS_REPLY_STRING) {
evhttp_send_reply(cmd->rq, 400, "Bad request", NULL);
return;
}
if(reply->element[1]->type != REDIS_REPLY_STRING) {
ct = reply->element[1]->str;
} else {
ct = "binary/octet-stream";
}
/* send reply */
format_send_reply(cmd, reply->element[0]->str, reply->element[0]->len, ct);
}

@ -0,0 +1,12 @@
#ifndef CUSTOM_TYPE_H
#define CUSTOM_TYPE_H
#include <hiredis/hiredis.h>
#include <hiredis/async.h>
struct cmd;
void
custom_type_reply(redisAsyncContext *c, void *r, void *privdata);
#endif
Loading…
Cancel
Save