Skip to content

Commit 13c96e0

Browse files
committed
out_http: Add capability to handle user_agent option
Signed-off-by: rja5 <rallen99@gmail.com>
1 parent 0d7bfb9 commit 13c96e0

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

plugins/out_http/http.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ static struct flb_config_map config_map[] = {
743743
0, FLB_TRUE, offsetof(struct flb_out_http, oauth2_config.client_secret),
744744
"OAuth2 client_secret"
745745
},
746+
{
747+
FLB_CONFIG_MAP_STR, "oauth2.user_agent", NULL,
748+
0, FLB_TRUE, offsetof(struct flb_out_http, oauth2_config.user_agent),
749+
"Optional User-Agent header for OAuth2 token requests"
750+
},
746751
{
747752
FLB_CONFIG_MAP_STR, "oauth2.scope", NULL,
748753
0, FLB_TRUE, offsetof(struct flb_out_http, oauth2_config.scope),

src/flb_oauth2.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ struct flb_config_map oauth2_config_map[] = {
6767
0, FLB_TRUE, offsetof(struct flb_oauth2_config, client_secret),
6868
"OAuth2 client_secret"
6969
},
70+
{
71+
FLB_CONFIG_MAP_STR, "oauth2.user_agent", NULL,
72+
0, FLB_TRUE, offsetof(struct flb_oauth2_config, user_agent),
73+
"Optional User-Agent header for OAuth2 token requests"
74+
},
7075
{
7176
FLB_CONFIG_MAP_STR, "oauth2.scope", NULL,
7277
0, FLB_TRUE, offsetof(struct flb_oauth2_config, scope),
@@ -185,6 +190,7 @@ static void oauth2_apply_defaults(struct flb_oauth2_config *cfg)
185190
cfg->token_url = NULL;
186191
cfg->client_id = NULL;
187192
cfg->client_secret = NULL;
193+
cfg->user_agent = NULL;
188194
cfg->scope = NULL;
189195
cfg->audience = NULL;
190196
cfg->resource = NULL;
@@ -243,6 +249,15 @@ static int oauth2_clone_config(struct flb_oauth2_config *dst,
243249
}
244250
}
245251

252+
if (src->user_agent) {
253+
dst->user_agent = flb_sds_create(src->user_agent);
254+
if (!dst->user_agent) {
255+
flb_errno();
256+
flb_oauth2_config_destroy(dst);
257+
return -1;
258+
}
259+
}
260+
246261
if (src->scope) {
247262
dst->scope = flb_sds_create(src->scope);
248263
if (!dst->scope) {
@@ -324,6 +339,8 @@ void flb_oauth2_config_destroy(struct flb_oauth2_config *cfg)
324339
cfg->client_id = NULL;
325340
flb_sds_destroy(cfg->client_secret);
326341
cfg->client_secret = NULL;
342+
flb_sds_destroy(cfg->user_agent);
343+
cfg->user_agent = NULL;
327344
flb_sds_destroy(cfg->scope);
328345
cfg->scope = NULL;
329346
flb_sds_destroy(cfg->audience);
@@ -1114,6 +1131,14 @@ static int oauth2_http_request(struct flb_oauth2 *ctx, flb_sds_t body)
11141131
FLB_OAUTH2_HTTP_ENCODING,
11151132
sizeof(FLB_OAUTH2_HTTP_ENCODING) - 1);
11161133

1134+
if (ctx->cfg.user_agent) {
1135+
flb_http_add_header(c,
1136+
"User-Agent",
1137+
10,
1138+
ctx->cfg.user_agent,
1139+
flb_sds_len(ctx->cfg.user_agent));
1140+
}
1141+
11171142
if (ctx->cfg.auth_method == FLB_OAUTH2_AUTH_METHOD_BASIC &&
11181143
ctx->cfg.client_id && ctx->cfg.client_secret) {
11191144
ret = flb_http_basic_auth(c, ctx->cfg.client_id, ctx->cfg.client_secret);

0 commit comments

Comments
 (0)