Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_websocket: Add ability to provide additional headers #8536

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/out_websocket/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);

Expand Down Expand Up @@ -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 to the initial HTTP request. Multiple headers can be set"
},
/* EOF */
{0}
};
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_websocket/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading