diff --git a/plugins/out_websocket/websocket.c b/plugins/out_websocket/websocket.c index 34d6d41a079..1cd715f1c40 100644 --- a/plugins/out_websocket/websocket.c +++ b/plugins/out_websocket/websocket.c @@ -43,6 +43,10 @@ static int flb_ws_handshake(struct flb_connection *u_conn, int ret; size_t bytes_sent; struct flb_http_client *c; + struct mk_list *head; + struct flb_config_map_val *mv; + struct flb_slist_entry *key = NULL; + struct flb_slist_entry *val = NULL; if (!u_conn) { flb_error("[output_ws] upstream connection error"); @@ -63,6 +67,16 @@ static int flb_ws_handshake(struct flb_connection *u_conn, flb_http_add_header(c, "Sec-WebSocket-Key", 17, "dGhlIHNhbXBsZSBub25jZQ==", 24); flb_http_add_header(c, "Sec-WebSocket-Version", 21, "13", 2); + /* Append additional headers from configuration */ + flb_config_map_foreach(head, mv, ctx->headers) { + key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head); + val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head); + + flb_http_add_header(c, + key->str, flb_sds_len(key->str), + val->str, flb_sds_len(val->str)); + } + /* Perform request*/ ret = flb_http_do(c, &bytes_sent); @@ -315,6 +329,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_out_ws, json_date_key), "Specify the name of the date field in output" }, + { + FLB_CONFIG_MAP_SLIST_1, "header", NULL, + FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_out_ws, headers), + "Add a HTTP header key/value pair. Multiple headers can be set" + }, /* EOF */ {0} }; diff --git a/plugins/out_websocket/websocket.h b/plugins/out_websocket/websocket.h index f215b0f2c85..7769c7ae30f 100644 --- a/plugins/out_websocket/websocket.h +++ b/plugins/out_websocket/websocket.h @@ -47,6 +47,9 @@ struct flb_out_ws { time_t last_input_timestamp; int idle_interval; + /* Arbitrary HTTP headers */ + struct mk_list *headers; + /* Plugin instance */ struct flb_output_instance *ins; };