Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started adding support for a custom content-type in a second key.
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |