-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Fix: Preserve HTTP headers in ParallelChannel sub-calls #3061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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. | ||||||||||||||||||
| 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); | ||||||||||||||||||
|
||||||||||||||||||
| sub_hdr.AppendHeader(it->first, it->second); | |
| sub_hdr.SetHeader(it->first, it->second); |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.