Skip to content

Commit 612351d

Browse files
author
Grok Compression
committed
http auth: support up to 16 custom headers
1 parent 94be80c commit 612351d

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

src/lib/core/grok.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ typedef struct _grk_stream_params
582582
char username[129]; /* AWS access key ID: max 128 chars + null */
583583
char password[129]; /* Secret access key: max 128 chars + null */
584584
char bearer_token[4097]; /* Session token: up to 4096 chars + null */
585-
char custom_header[1024]; /* Single header: fits within 8KB total limit */
585+
#define GRK_MAX_CUSTOM_HEADERS 16
586+
char custom_headers[GRK_MAX_CUSTOM_HEADERS][1024]; /* Custom HTTP headers */
587+
uint8_t
588+
num_custom_headers; /* Number of entries in custom_headers[] (0..GRK_MAX_CUSTOM_HEADERS) */
586589
char region[64]; /* Region code: max 50 chars + buffer */
587590

588591
/* 5 S3 Endpoint Configuration (for S3-compatible services like MinIO) */

src/lib/core/stream/StreamGenerator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ IStream* StreamGenerator::createCurlFetchStream(void)
128128
auth.session_token_ = streamParams_.bearer_token;
129129
if(streamParams_.region[0])
130130
auth.region_ = streamParams_.region;
131-
if(streamParams_.custom_header[0])
132-
auth.custom_header_ = streamParams_.custom_header;
131+
for(uint8_t i = 0; i < streamParams_.num_custom_headers; ++i)
132+
{
133+
if(streamParams_.custom_headers[i][0])
134+
auth.custom_headers_.emplace_back(streamParams_.custom_headers[i]);
135+
}
133136
if(streamParams_.s3_endpoint[0])
134137
auth.s3_endpoint_ = streamParams_.s3_endpoint;
135138
auth.s3_use_https_ = streamParams_.s3_use_https;

src/lib/core/stream/StreamGenerator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class StreamGenerator
7272
safe_strcpy(streamParams_.username, src->username);
7373
safe_strcpy(streamParams_.password, src->password);
7474
safe_strcpy(streamParams_.bearer_token, src->bearer_token);
75-
safe_strcpy(streamParams_.custom_header, src->custom_header);
75+
streamParams_.num_custom_headers = src->num_custom_headers;
76+
for(uint8_t i = 0; i < src->num_custom_headers; ++i)
77+
safe_strcpy(streamParams_.custom_headers[i], src->custom_headers[i]);
7678
safe_strcpy(streamParams_.region, src->region);
7779

7880
safe_strcpy(streamParams_.s3_endpoint, src->s3_endpoint);

src/lib/core/stream/fetchers/FetchCommon.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct FetchAuth
4343
std::string username_;
4444
std::string password_;
4545
std::string bearer_token_;
46-
std::string custom_header_;
46+
std::vector<std::string> custom_headers_;
4747
std::string region_;
4848
std::string session_token_; // Added for AWS_SESSION_TOKEN
4949
std::string s3_endpoint_; // Custom S3 endpoint URL (e.g. MinIO)
@@ -80,9 +80,10 @@ struct FetchAuth
8080
uint32_t retry_delay_ = 0;
8181

8282
FetchAuth() = default;
83-
FetchAuth(const std::string& u, const std::string& p, const std::string& t, const std::string& h,
84-
const std::string& r = "", const std::string& st = "")
85-
: username_(u), password_(p), bearer_token_(t), custom_header_(h), region_(r),
83+
FetchAuth(const std::string& u, const std::string& p, const std::string& t,
84+
const std::vector<std::string>& h = {}, const std::string& r = "",
85+
const std::string& st = "")
86+
: username_(u), password_(p), bearer_token_(t), custom_headers_(h), region_(r),
8687
session_token_(st)
8788
{}
8889
};

src/lib/core/stream/fetchers/HTTPFetcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ class HTTPFetcher : public CurlFetcher
100100
grklog.debug("GRK_HTTP_HEADER_FILE set to %s (not fully implemented)", header_file);
101101
}
102102

103-
// Log custom header and bearer token usage
104-
if(!auth_.custom_header_.empty())
103+
// Log custom headers and bearer token usage
104+
for(const auto& hdr : auth_.custom_headers_)
105105
{
106-
grklog.debug("Using custom header: %s", auth_.custom_header_.c_str());
106+
grklog.debug("Using custom header: %s", hdr.c_str());
107107
}
108108
if(!auth_.bearer_token_.empty())
109109
{
@@ -113,10 +113,10 @@ class HTTPFetcher : public CurlFetcher
113113

114114
curl_slist* prepareAuthHeaders(curl_slist* headers) override
115115
{
116-
// Add custom header from FetchAuth if provided
117-
if(!auth_.custom_header_.empty())
116+
// Add custom headers from FetchAuth if provided
117+
for(const auto& hdr : auth_.custom_headers_)
118118
{
119-
headers = curl_slist_append(headers, auth_.custom_header_.c_str());
119+
headers = curl_slist_append(headers, hdr.c_str());
120120
}
121121

122122
// Add Authorization header for bearer token if provided

0 commit comments

Comments
 (0)