feat(lander): support DELETE requests
This commit is contained in:
parent
a4ad8c246e
commit
3d48ee8019
4 changed files with 42 additions and 1 deletions
|
|
@ -19,6 +19,14 @@ http_route lander_routes[] = {
|
|||
.steps_res = {http_loop_step_write_header, lander_stream_body_to_client,
|
||||
NULL},
|
||||
},
|
||||
{
|
||||
.type = http_route_regex,
|
||||
.method = http_delete,
|
||||
.path = "^/([^/]+)$",
|
||||
.steps = {http_loop_step_auth, lander_remove_entry, NULL},
|
||||
.steps_res = {http_loop_step_write_header, http_loop_step_write_body,
|
||||
NULL},
|
||||
},
|
||||
{
|
||||
.type = http_route_regex,
|
||||
.method = http_post,
|
||||
|
|
|
|||
29
src/lander/lander_delete.c
Normal file
29
src/lander/lander_delete.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "lander.h"
|
||||
|
||||
bool lander_remove_entry(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
lander_ctx *c_ctx = ctx->c;
|
||||
http_loop_gctx *gctx = ctx->g;
|
||||
lander_gctx *c_gctx = gctx->c;
|
||||
|
||||
const char *key_s = &ctx->req.path[ctx->req.regex_groups[1].rm_so];
|
||||
int key_len = ctx->req.regex_groups[1].rm_eo - ctx->req.regex_groups[1].rm_so;
|
||||
|
||||
lsm_str *key;
|
||||
lsm_str_init_copy_n(&key, (char *)key_s, key_len);
|
||||
|
||||
switch (lsm_store_open_write(&c_ctx->entry, c_gctx->store, key)) {
|
||||
case lsm_error_ok:
|
||||
break;
|
||||
case lsm_error_not_found:
|
||||
ctx->res.status = http_not_found;
|
||||
return true;
|
||||
default:
|
||||
ctx->res.status = http_internal_server_error;
|
||||
return true;
|
||||
}
|
||||
|
||||
lsm_entry_remove(c_ctx->entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue