Skip to content

Commit 8bd6ab8

Browse files
out_es: custom added ability ot set custom HTTP headers
Signed-off-by: Andrii Chubatiuk <[email protected]>
1 parent 41b90b7 commit 8bd6ab8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

plugins/out_es/es.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
817817
struct flb_http_client *c;
818818
flb_sds_t signature = NULL;
819819
int compressed = FLB_FALSE;
820+
struct mk_list *head;
821+
struct flb_config_map_val *mv;
822+
struct flb_slist_entry *key = NULL;
823+
struct flb_slist_entry *val = NULL;
820824

821825
/* Get upstream connection */
822826
u_conn = flb_upstream_conn_get(ctx->u);
@@ -874,6 +878,16 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
874878

875879
flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20);
876880

881+
/* Arbitrary additional headers */
882+
flb_config_map_foreach(head, mv, ctx->headers) {
883+
key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
884+
val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
885+
886+
flb_http_add_header(c,
887+
key->str, flb_sds_len(key->str),
888+
val->str, flb_sds_len(val->str));
889+
}
890+
877891
if (ctx->http_user && ctx->http_passwd) {
878892
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
879893
}
@@ -1023,6 +1037,14 @@ static struct flb_config_map config_map[] = {
10231037
"Password for user defined in HTTP_User"
10241038
},
10251039

1040+
/* Arbitrary HTTP headers */
1041+
{
1042+
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
1043+
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_elasticsearch, headers),
1044+
"Add a HTTP header key/value pair. Multiple headers can be set"
1045+
},
1046+
1047+
10261048
/* HTTP Compression */
10271049
{
10281050
FLB_CONFIG_MAP_STR, "compress", NULL,

plugins/out_es/es.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct flb_elasticsearch {
5151
char *type;
5252
int suppress_type_name;
5353

54+
/* Arbitrary HTTP headers */
55+
struct mk_list *headers;
56+
5457
/* HTTP Auth */
5558
char *http_user;
5659
char *http_passwd;

0 commit comments

Comments
 (0)