feat(lander): support DELETE requests
parent
a4ad8c246e
commit
3d48ee8019
|
@ -4,7 +4,7 @@
|
|||
#include "http_loop.h"
|
||||
#include "lsm/store.h"
|
||||
|
||||
extern http_route lander_routes[4];
|
||||
extern http_route lander_routes[5];
|
||||
|
||||
typedef struct lander_gctx {
|
||||
const char *data_dir;
|
||||
|
@ -57,4 +57,6 @@ bool lander_get_entry_lsm(event_loop_conn *conn);
|
|||
|
||||
bool lander_post_redirect_body_to_attr(event_loop_conn *conn);
|
||||
|
||||
bool lander_remove_entry(event_loop_conn *conn);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -151,6 +151,8 @@ lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle) {
|
|||
return res;
|
||||
}
|
||||
|
||||
fflush(store->idx.f);
|
||||
|
||||
// Remove data file if present
|
||||
if (entry->data_len > 0) {
|
||||
if (handle->f != NULL) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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…
Reference in New Issue