From 0368bd06968bc2ddec0451e4fa04a022a62ce4c0 Mon Sep 17 00:00:00 2001 From: Simonel David Date: Fri, 31 Jan 2025 18:29:53 +0200 Subject: [PATCH] s3 output plugin: added new variable to enable or disable headers When uploading an object to an AWS S3 bucket, a Content-Encoding header is automatically added to the object. When this object is later downloaded, web browsers recognize this header and automatically decompress the file. This behavior can lead to misleading file types across different operating systems, potentially causing compatibility issues or unexpected file handling. --- plugins/out_s3/s3.c | 9 +++++++-- plugins/out_s3/s3.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index 3b1edafbdab..3c919c3bc04 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -141,7 +141,7 @@ int create_headers(struct flb_s3 *ctx, char *body_md5, if (ctx->content_type != NULL) { headers_len++; } - if (ctx->compression == FLB_AWS_COMPRESS_GZIP) { + if (ctx->compression == FLB_AWS_COMPRESS_GZIP && ctx->enable_content_encoding_header) { headers_len++; } if (ctx->canned_acl != NULL) { @@ -171,7 +171,7 @@ int create_headers(struct flb_s3 *ctx, char *body_md5, s3_headers[n].val_len = strlen(ctx->content_type); n++; } - if (ctx->compression == FLB_AWS_COMPRESS_GZIP) { + if (ctx->compression == FLB_AWS_COMPRESS_GZIP && ctx->enable_content_encoding_header) { s3_headers[n] = content_encoding_header; n++; } @@ -2376,6 +2376,11 @@ static struct flb_config_map config_map[] = { "Defaults to no compression. " "If 'gzip' is selected, the Content-Encoding HTTP Header will be set to 'gzip'." }, + { + FLB_CONFIG_MAP_BOOL, "enable_content_encoding_header", "true", + 0, FLB_TRUE, offsetof(struct flb_s3, enable_content_encoding_header), + "Set to false to disable the Content-Encoding: gzip header." + }, { FLB_CONFIG_MAP_STR, "content_type", NULL, 0, FLB_FALSE, 0, diff --git a/plugins/out_s3/s3.h b/plugins/out_s3/s3.h index e51d39f2419..a6235e2aa97 100644 --- a/plugins/out_s3/s3.h +++ b/plugins/out_s3/s3.h @@ -119,6 +119,7 @@ struct flb_s3 { int send_content_md5; int static_file_path; int compression; + int enable_content_encoding_header; int port; int insecure; size_t store_dir_limit_size;