Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/brpc/parallel_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to check if sub-controller headers has exists key before AppendHeader or SetHeader? Avoid overwrite existing header.

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);
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using AppendHeader may result in duplicate headers if the sub-controller already has headers with the same name. Consider using SetHeader instead to avoid potential header duplication, or check if the header already exists before appending.

Suggested change
sub_hdr.AppendHeader(it->first, it->second);
sub_hdr.SetHeader(it->first, it->second);

Copilot uses AI. Check for mistakes.
}
Comment on lines +147 to +151
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The check for empty headers is redundant since the for loop will naturally handle empty header collections. This condition can be removed to simplify the code.

Suggested change
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);
}
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);

Copilot uses AI. Check for mistakes.
}
}
}
// Setup the map for finding sub_done of i-th sub_channel
if (ndone != nchan) {
Expand Down
Loading