Compare commits

...

2 Commits

Author SHA1 Message Date
Jef Roosens e44b7d0e5f
fix(lander): remove small mem leak
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/docker Pipeline was successful Details
2023-12-09 12:48:32 +01:00
Jef Roosens 4ae1355cec
feat(lander): re-add Server header 2023-12-09 12:34:02 +01:00
5 changed files with 19 additions and 1 deletions

View File

@ -85,6 +85,8 @@ lnm_err lnm_http_loop_run(lnm_http_loop *hl, uint16_t port);
void lnm_http_loop_set_api_key(lnm_http_loop *hl, const char *api_key);
void lnm_http_loop_set_server(lnm_http_loop *hl, const char *value);
/**
* Represents what state an HTTP loop request is currently in.
*/
@ -118,6 +120,7 @@ typedef struct lnm_http_loop_gctx {
lnm_http_ctx_reset_fn ctx_reset;
lnm_http_ctx_free_fn ctx_free;
const char *api_key;
const char *server;
void *c;
} lnm_http_loop_gctx;

View File

@ -131,3 +131,8 @@ void lnm_http_loop_set_api_key(lnm_http_loop *hl, const char *api_key) {
lnm_http_loop_gctx *gctx = hl->gctx;
gctx->api_key = api_key;
}
void lnm_http_loop_set_server(lnm_http_loop *hl, const char *server) {
lnm_http_loop_gctx *gctx = hl->gctx;
gctx->server = server;
}

View File

@ -158,6 +158,11 @@ void lnm_http_loop_state_process_add_headers(lnm_http_conn *conn) {
lnm_http_res_add_header_len(res, lnm_http_header_content_length, buf, digits,
true);
if (ctx->g->server != NULL) {
lnm_http_res_add_header(res, lnm_http_header_server, (char *)ctx->g->server,
false);
}
ctx->state = lnm_http_loop_state_write_status_line;
}

View File

@ -121,8 +121,10 @@ lnm_http_step_err lander_get_entry(lnm_http_conn *conn) {
lsm_str *key;
lsm_str_init_copy_n(&key, (char *)key_s, key_len);
lsm_error lsm_res = lsm_store_open_read(&c_ctx->entry, c_gctx->store, key);
lsm_str_free(key);
switch (lsm_store_open_read(&c_ctx->entry, c_gctx->store, key)) {
switch (lsm_res) {
case lsm_error_ok:
break;
case lsm_error_not_found:

View File

@ -7,6 +7,8 @@
#include "lander.h"
#include "log.h"
const char *lander_server = "lander/" LANDER_VERSION;
lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) {
lnm_http_loop *hl;
lnm_http_step *step = NULL;
@ -15,6 +17,7 @@ lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) {
(lnm_http_ctx_reset_fn)lander_ctx_reset,
(lnm_http_ctx_free_fn)lander_ctx_free);
lnm_http_loop_set_api_key(hl, api_key);
lnm_http_loop_set_server(hl, lander_server);
lnm_http_step_init(&step, lander_get_index);
lnm_http_route_init_literal(&route, lnm_http_method_get, "/", step);