From d6d8c964b2814fe9c631b4f6a01ca4af4409779c Mon Sep 17 00:00:00 2001 From: Wesley Pettit Date: Tue, 1 Nov 2022 11:32:19 -0700 Subject: [PATCH] aws: different user agent on windows vs linux Signed-off-by: Wesley Pettit --- src/aws/flb_aws_util.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/aws/flb_aws_util.c b/src/aws/flb_aws_util.c index f96de4e6af4..3ca93bd9a8f 100644 --- a/src/aws/flb_aws_util.c +++ b/src/aws/flb_aws_util.c @@ -47,6 +47,16 @@ #define AWS_ECS_METADATA_URI "ECS_CONTAINER_METADATA_URI_V4" #define FLB_MAX_AWS_RESP_BUFFER_SIZE 0 /* 0 means unlimited capacity as per requirement */ +#ifdef FLB_SYSTEM_WINDOWS +#define FLB_AWS_BASE_USER_AGENT "aws-fluent-bit-plugin-windows" +#define FLB_AWS_BASE_USER_AGENT_FORMAT "aws-fluent-bit-plugin-windows-%s" +#define FLB_AWS_BASE_USER_AGENT_LEN 29 +#else +#define FLB_AWS_BASE_USER_AGENT "aws-fluent-bit-plugin" +#define FLB_AWS_BASE_USER_AGENT_FORMAT "aws-fluent-bit-plugin-%s" +#define FLB_AWS_BASE_USER_AGENT_LEN 21 +#endif + struct flb_http_client *request_do(struct flb_aws_client *aws_client, int method, const char *uri, const char *body, size_t body_len, @@ -369,16 +379,21 @@ struct flb_http_client *request_do(struct flb_aws_client *aws_client, /* Add AWS Fluent Bit user agent header */ if (strcasecmp(aws_client->extra_user_agent, AWS_USER_AGENT_NONE) == 0) { ret = flb_http_add_header(c, "User-Agent", 10, - "aws-fluent-bit-plugin", 21); + FLB_AWS_BASE_USER_AGENT, FLB_AWS_BASE_USER_AGENT_LEN); } else { user_agent_prefix = flb_sds_create_size(64); - tmp = flb_sds_printf(&user_agent_prefix, "aws-fluent-bit-plugin-%s", + if (!user_agent_prefix) { + flb_errno(); + flb_error("[aws_client] failed to create user agent"); + goto error; + } + tmp = flb_sds_printf(&user_agent_prefix, FLB_AWS_BASE_USER_AGENT_FORMAT, aws_client->extra_user_agent); if (!tmp) { flb_errno(); flb_sds_destroy(user_agent_prefix); - flb_error("[aws_client] failed to fetch user agent"); + flb_error("[aws_client] failed to create user agent"); goto error; } user_agent_prefix = tmp;