-
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?
Fix: Preserve HTTP headers in ParallelChannel sub-calls #3061
Conversation
Add judgement to avoid create new object when cntl dont have http_request
Fix: Preserve HTTP headers in ParallelChannel sub-callsThere 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.
Pull Request Overview
This PR fixes an issue where HTTP headers set on parent controllers are lost when making sub-calls through ParallelChannel. The fix ensures that application-set headers like Authorization are properly propagated to each sub-controller.
- Adds header propagation logic to preserve parent controller headers in sub-calls
- Maintains backward compatibility by only copying headers when they exist
- Improves functionality for applications that rely on HTTP headers for authentication/authorization
| 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); | ||
| } |
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); |
| 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); |
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.
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.
| sub_hdr.AppendHeader(it->first, it->second); | |
| sub_hdr.SetHeader(it->first, it->second); |
| 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. |
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.
Problem
When using ParallelChannel, HTTP headers set on the parent controller (e.g., Authorization headers) are lost during sub-calls because they are not propagated to the sub-controllers.
Solution