From 3b2a904ddceffd46549276b9e5ae3e519fbe7b30 Mon Sep 17 00:00:00 2001 From: wuying Date: Mon, 11 Aug 2025 12:03:01 +0800 Subject: [PATCH 1/2] Copy Header from Parent controller to avoid lose header infomation --- src/brpc/parallel_channel.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/brpc/parallel_channel.cpp b/src/brpc/parallel_channel.cpp index 130712bfb9..10c5dd1869 100644 --- a/src/brpc/parallel_channel.cpp +++ b/src/brpc/parallel_channel.cpp @@ -139,6 +139,14 @@ class ParallelChannelDone : public google::protobuf::Closure { new (d->sub_done(i)) SubDone; d->sub_done(i)->cntl.ApplyClientSettings(settings); d->sub_done(i)->cntl.allow_done_to_run_in_place(); + + // Propagate all HTTP headers from parent controller to sub-controllers. + // This preserves application-set headers (e.g., Authorization) on each sub-call. + auto& parent_hdr = cntl->http_request(); + auto& sub_hdr = d->sub_done(i)->cntl.http_request(); + for (auto it = parent_hdr.HeaderBegin(); it != parent_hdr.HeaderEnd(); ++it) { + sub_hdr.AppendHeader(it->first, it->second); + } } // Setup the map for finding sub_done of i-th sub_channel if (ndone != nchan) { From 14a117133ccaacdc95ac9df912898694e2fc8752 Mon Sep 17 00:00:00 2001 From: Ying Wu <43434782+XiaoYingGee@users.noreply.github.com> Date: Tue, 12 Aug 2025 10:48:07 +0800 Subject: [PATCH 2/2] Update parallel_channel.cpp Add judgement to avoid create new object when cntl dont have http_request --- src/brpc/parallel_channel.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/brpc/parallel_channel.cpp b/src/brpc/parallel_channel.cpp index 10c5dd1869..28c38aab45 100644 --- a/src/brpc/parallel_channel.cpp +++ b/src/brpc/parallel_channel.cpp @@ -142,10 +142,14 @@ class ParallelChannelDone : public google::protobuf::Closure { // Propagate all HTTP headers from parent controller to sub-controllers. // This preserves application-set headers (e.g., Authorization) on each sub-call. - auto& parent_hdr = cntl->http_request(); - auto& sub_hdr = d->sub_done(i)->cntl.http_request(); - for (auto it = parent_hdr.HeaderBegin(); it != parent_hdr.HeaderEnd(); ++it) { - sub_hdr.AppendHeader(it->first, it->second); + if (cntl->has_http_request()) { + auto& parent_hdr = cntl->http_request(); + if (parent_hdr.HeaderBegin() != parent_hdr.HeaderEnd()) { + auto& sub_hdr = d->sub_done(i)->cntl.http_request(); + for (auto it = parent_hdr.HeaderBegin(); it != parent_hdr.HeaderEnd(); ++it) { + sub_hdr.AppendHeader(it->first, it->second); + } + } } } // Setup the map for finding sub_done of i-th sub_channel