aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoakim Lindqvist <[email protected]>2026-04-14 16:56:49 +0200
committerGitHub Enterprise <[email protected]>2026-04-14 16:56:49 +0200
commit7980f3be6566c0a06c82765f595b6c591ed9a0fa (patch)
treeffe8decaebb89fcb9dd355c47dff51e825dd98d4 /src
parent5.8.4 (diff)
downloadzen-7980f3be6566c0a06c82765f595b6c591ed9a0fa.tar.xz
zen-7980f3be6566c0a06c82765f595b6c591ed9a0fa.zip
fix OAuth client credentials content type override (#957)
- Bugfix: OAuth client credentials token request now sends correct `application/x-www-form-urlencoded` content type - Improvement: HTTP client Content-Type in additional headers now overrides the payload content type
Diffstat (limited to 'src')
-rw-r--r--src/zenhttp/clients/httpclientcurlhelpers.h5
-rw-r--r--src/zenhttp/httpclient_test.cpp11
-rw-r--r--src/zenhttp/httpclientauth.cpp2
3 files changed, 16 insertions, 2 deletions
diff --git a/src/zenhttp/clients/httpclientcurlhelpers.h b/src/zenhttp/clients/httpclientcurlhelpers.h
index 0605a30f6..cb5f5d9a9 100644
--- a/src/zenhttp/clients/httpclientcurlhelpers.h
+++ b/src/zenhttp/clients/httpclientcurlhelpers.h
@@ -255,8 +255,13 @@ BuildHeaderList(const HttpClient::KeyValueMap& AdditionalHeader,
Headers = curl_slist_append(Headers, AuthHeader.c_str());
}
+ bool HasContentTypeOverride = AdditionalHeader->contains("Content-Type");
for (const auto& [Key, Value] : ExtraHeaders)
{
+ if (HasContentTypeOverride && Key == "Content-Type")
+ {
+ continue;
+ }
ExtendableStringBuilder<128> HeaderLine;
HeaderLine << Key << ": " << Value;
Headers = curl_slist_append(Headers, HeaderLine.c_str());
diff --git a/src/zenhttp/httpclient_test.cpp b/src/zenhttp/httpclient_test.cpp
index 67cbaea9b..deaeca2a8 100644
--- a/src/zenhttp/httpclient_test.cpp
+++ b/src/zenhttp/httpclient_test.cpp
@@ -414,6 +414,17 @@ TEST_CASE("httpclient.post")
CHECK_EQ(Resp.AsText(), "{\"key\":\"value\"}");
}
+ SUBCASE("POST with content type override via additional header")
+ {
+ const char* Payload = "test payload";
+ IoBuffer Buf(IoBuffer::Clone, Payload, strlen(Payload));
+
+ HttpClient::Response Resp = Client.Post("/api/test/echo", Buf, ZenContentType::kJSON, {{"Content-Type", "text/plain"}});
+ CHECK(Resp.IsSuccess());
+ CHECK_EQ(Resp.AsText(), "test payload");
+ CHECK_EQ(Resp.ResponsePayload.GetContentType(), ZenContentType::kText);
+ }
+
SUBCASE("POST with CbObject payload round-trip")
{
CbObjectWriter Writer;
diff --git a/src/zenhttp/httpclientauth.cpp b/src/zenhttp/httpclientauth.cpp
index 0432e50ef..26a7298b3 100644
--- a/src/zenhttp/httpclientauth.cpp
+++ b/src/zenhttp/httpclientauth.cpp
@@ -50,8 +50,6 @@ namespace zen { namespace httpclientauth {
IoBuffer Payload{IoBuffer::Wrap, Body.data(), Body.size()};
- // TODO: ensure this gets the right Content-Type passed along
-
HttpClient::Response Response = Http.Post("", Payload, {{"Content-Type", "application/x-www-form-urlencoded"}});
if (!Response || Response.StatusCode != HttpResponseCode::OK)