Skip to content

Commit 7209a5c

Browse files
Update plugins/out_es/es.c
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Todd Kennedy <[email protected]>
1 parent 69caba0 commit 7209a5c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

plugins/out_es/es.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -890,28 +890,21 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
890890
flb_http_basic_auth(c, ctx->cloud_user, ctx->cloud_passwd);
891891
}
892892
else if (ctx->http_api_key) {
893-
header_buffer = flb_sds_create_size(strlen(ctx->http_api_key) + 64);
894-
895-
if (header_buffer == NULL) {
896-
flb_error("[out_es] failed to create header buffer");
893+
header_line = flb_sds_printf(NULL, "ApiKey %s", ctx->http_api_key);
894+
if (header_line == NULL) {
895+
flb_plg_error(ctx->ins, "failed to format API key auth header");
896+
goto retry;
897897
}
898-
else {
899-
header_line = flb_sds_printf(&header_buffer, "ApiKey %s", ctx->http_api_key);
900-
901-
if (header_line != NULL) {
902-
flb_http_add_header(c,
903-
FLB_HTTP_HEADER_AUTH,
904-
strlen(FLB_HTTP_HEADER_AUTH),
905-
header_line,
906-
flb_sds_len(header_line));
907-
}
908-
else {
909-
flb_sds_destroy(header_buffer);
910-
goto error;
911-
}
912898

913-
flb_sds_destroy(header_buffer);
899+
if (flb_http_add_header(c,
900+
FLB_HTTP_HEADER_AUTH, strlen(FLB_HTTP_HEADER_AUTH),
901+
header_line, flb_sds_len(header_line)) != 0) {
902+
flb_plg_error(ctx->ins, "failed to add API key auth header");
903+
flb_sds_destroy(header_line);
904+
goto retry;
914905
}
906+
907+
flb_sds_destroy(header_line);
915908
}
916909

917910
#ifdef FLB_HAVE_AWS

0 commit comments

Comments
 (0)