From 8cd8199e4bca3c46d7f4cc93b9f57a7d661d2f43 Mon Sep 17 00:00:00 2001 From: Nicholas Nezis Date: Tue, 16 Sep 2025 11:55:58 -0400 Subject: [PATCH 1/4] out_http: Added PUT support Signed-off-by: Nicholas Nezis --- plugins/out_http/http.c | 29 +++++++++++++++++------------ plugins/out_http/http.h | 3 +++ plugins/out_http/http_conf.c | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index 88b62673742..ae84e96f41e 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -109,10 +109,10 @@ static void append_headers(struct flb_http_client *c, } } -static int http_post(struct flb_out_http *ctx, - const void *body, size_t body_len, - const char *tag, int tag_len, - char **headers) +static int http_request(struct flb_out_http *ctx, + const void *body, size_t body_len, + const char *tag, int tag_len, + char **headers) { int ret = 0; int out_ret = FLB_OK; @@ -173,7 +173,7 @@ static int http_post(struct flb_out_http *ctx, /* Create HTTP client context */ - c = flb_http_client(u_conn, FLB_HTTP_POST, ctx->uri, + c = flb_http_client(u_conn, ctx->http_method, ctx->uri, payload_buf, payload_size, ctx->host, ctx->port, ctx->proxy, 0); @@ -598,8 +598,8 @@ static int post_all_requests(struct flb_out_http *ctx, } if (body_found && headers_found) { - flb_plg_trace(ctx->ins, "posting record %zu", record_count++); - ret = http_post(ctx, body, body_size, event_chunk->tag, + flb_plg_trace(ctx->ins, "sending record %zu", record_count++); + ret = http_request(ctx, body, body_size, event_chunk->tag, flb_sds_len(event_chunk->tag), headers); } else { @@ -649,15 +649,15 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk, (ctx->out_format == FLB_PACK_JSON_FORMAT_STREAM) || (ctx->out_format == FLB_PACK_JSON_FORMAT_LINES) || (ctx->out_format == FLB_HTTP_OUT_GELF)) { - ret = http_post(ctx, out_body, out_size, - event_chunk->tag, flb_sds_len(event_chunk->tag), NULL); + ret = http_request(ctx, out_body, out_size, + event_chunk->tag, flb_sds_len(event_chunk->tag), NULL); flb_sds_destroy(out_body); } else { /* msgpack */ - ret = http_post(ctx, - event_chunk->data, event_chunk->size, - event_chunk->tag, flb_sds_len(event_chunk->tag), NULL); + ret = http_request(ctx, + event_chunk->data, event_chunk->size, + event_chunk->tag, flb_sds_len(event_chunk->tag), NULL); } } @@ -759,6 +759,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_out_http, uri), "Specify an optional HTTP URI for the target web server, e.g: /something" }, + { + FLB_CONFIG_MAP_STR, "http_method", "POST", + 0, FLB_FALSE, 0, + "Specify the HTTP method to use. Supported methods are POST and PUT" + }, /* Gelf Properties */ { diff --git a/plugins/out_http/http.h b/plugins/out_http/http.h index 4373f2c2e2a..2a0b3ca5c91 100644 --- a/plugins/out_http/http.h +++ b/plugins/out_http/http.h @@ -67,6 +67,9 @@ struct flb_out_http { char *host; int port; + /* HTTP method */ + int http_method; + /* GELF fields */ struct flb_gelf_fields gelf_fields; diff --git a/plugins/out_http/http_conf.c b/plugins/out_http/http_conf.c index 24f93ca94d8..18081884663 100644 --- a/plugins/out_http/http_conf.c +++ b/plugins/out_http/http_conf.c @@ -272,6 +272,23 @@ struct flb_out_http *flb_http_conf_create(struct flb_output_instance *ins, } } + /* HTTP method */ + ctx->http_method = FLB_HTTP_POST; + tmp = flb_output_get_property("http_method", ins); + if (tmp) { + if (strcasecmp(tmp, "POST") == 0) { + ctx->http_method = FLB_HTTP_POST; + } + else if (strcasecmp(tmp, "PUT") == 0) { + ctx->http_method = FLB_HTTP_PUT; + } + else { + flb_plg_error(ctx->ins, "invalid http_method option '%s'. Supported methods are POST and PUT", tmp); + flb_free(ctx); + return NULL; + } + } + ctx->u = upstream; ctx->uri = uri; ctx->host = ins->host.name; From 654d36cd7914512d9a25cafb5445421762214b85 Mon Sep 17 00:00:00 2001 From: Nicholas Nezis Date: Tue, 16 Sep 2025 14:25:20 -0400 Subject: [PATCH 2/4] out_http: Add HTTP client header in http_conf.c Signed-off-by: Nicholas Nezis --- plugins/out_http/http_conf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/out_http/http_conf.c b/plugins/out_http/http_conf.c index 18081884663..a9aa2596cae 100644 --- a/plugins/out_http/http_conf.c +++ b/plugins/out_http/http_conf.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifdef FLB_HAVE_SIGNV4 From 43ec901009f6abe38f68a40115f63ccccfff009d Mon Sep 17 00:00:00 2001 From: Nicholas Nezis Date: Tue, 16 Sep 2025 14:29:06 -0400 Subject: [PATCH 3/4] out_http: Rename post_all_requests to send_all_requests Signed-off-by: Nicholas Nezis --- plugins/out_http/http.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index ae84e96f41e..70b1059d265 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -529,7 +529,7 @@ static char **extract_headers(msgpack_object *obj) { return NULL; } -static int post_all_requests(struct flb_out_http *ctx, +static int send_all_requests(struct flb_out_http *ctx, const char *data, size_t size, flb_sds_t body_key, flb_sds_t headers_key, @@ -631,11 +631,11 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk, (void) i_ins; if (ctx->body_key) { - ret = post_all_requests(ctx, event_chunk->data, event_chunk->size, + ret = send_all_requests(ctx, event_chunk->data, event_chunk->size, ctx->body_key, ctx->headers_key, event_chunk); if (ret < 0) { flb_plg_error(ctx->ins, - "failed to post requests body key \"%s\"", ctx->body_key); + "failed to send requests body key \"%s\"", ctx->body_key); } } else { From 3f93aab0f2e098d0c62d109b7faf1c6cf4e25640 Mon Sep 17 00:00:00 2001 From: Nicholas Nezis Date: Tue, 16 Sep 2025 14:56:45 -0400 Subject: [PATCH 4/4] out_http: Improve logging for HTTP request sending Signed-off-by: Nicholas Nezis --- plugins/out_http/http.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index 70b1059d265..bf59fbe76d3 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -598,7 +598,9 @@ static int send_all_requests(struct flb_out_http *ctx, } if (body_found && headers_found) { - flb_plg_trace(ctx->ins, "sending record %zu", record_count++); + flb_plg_trace(ctx->ins, "sending record %zu via %s", + record_count++, + ctx->http_method == FLB_HTTP_POST ? "POST" : "PUT"); ret = http_request(ctx, body, body_size, event_chunk->tag, flb_sds_len(event_chunk->tag), headers); } @@ -635,7 +637,7 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk, ctx->body_key, ctx->headers_key, event_chunk); if (ret < 0) { flb_plg_error(ctx->ins, - "failed to send requests body key \"%s\"", ctx->body_key); + "failed to send requests using body key \"%s\"", ctx->body_key); } } else {