Skip to content

Commit 3b7beb3

Browse files
out_es: custom added ability ot set custom HTTP headers
Signed-off-by: AndrewChubatiuk <[email protected]>
1 parent e55ccbc commit 3b7beb3

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
@@ -810,6 +810,10 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
810810
struct flb_http_client *c;
811811
flb_sds_t signature = NULL;
812812
int compressed = FLB_FALSE;
813+
struct mk_list *head;
814+
struct flb_config_map_val *mv;
815+
struct flb_slist_entry *key = NULL;
816+
struct flb_slist_entry *val = NULL;
813817

814818
/* Get upstream connection */
815819
u_conn = flb_upstream_conn_get(ctx->u);
@@ -867,6 +871,16 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
867871

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

874+
/* Arbitrary additional headers */
875+
flb_config_map_foreach(head, mv, ctx->headers) {
876+
key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
877+
val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
878+
879+
flb_http_add_header(c,
880+
key->str, flb_sds_len(key->str),
881+
val->str, flb_sds_len(val->str));
882+
}
883+
870884
if (ctx->http_user && ctx->http_passwd) {
871885
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
872886
}
@@ -1016,6 +1030,14 @@ static struct flb_config_map config_map[] = {
10161030
"Password for user defined in HTTP_User"
10171031
},
10181032

1033+
/* Arbitrary HTTP headers */
1034+
{
1035+
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
1036+
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_elasticsearch, headers),
1037+
"Add a HTTP header key/value pair. Multiple headers can be set"
1038+
},
1039+
1040+
10191041
/* HTTP Compression */
10201042
{
10211043
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
@@ -42,6 +42,9 @@ struct flb_elasticsearch {
4242
char *type;
4343
char suppress_type_name;
4444

45+
/* Arbitrary HTTP headers */
46+
struct mk_list *headers;
47+
4548
/* HTTP Auth */
4649
char *http_user;
4750
char *http_passwd;

0 commit comments

Comments
 (0)