Skip to content

feat: add custom headers support for sync providers#1955

Closed
raflFaisal wants to merge 6 commits intoopen-feature:mainfrom
bookingcom:feat/sync-provider-headers
Closed

feat: add custom headers support for sync providers#1955
raflFaisal wants to merge 6 commits intoopen-feature:mainfrom
bookingcom:feat/sync-provider-headers

Conversation

@raflFaisal
Copy link
Copy Markdown

@raflFaisal raflFaisal commented Apr 29, 2026

Summary

Add support for custom headers in sync providers (HTTP and gRPC), configurable both globally via CLI flag and per-source in JSON configuration.

Problem

flagd's sync providers cannot inject custom request headers into outbound requests. This limits integration with environments where intermediaries (API gateways, reverse proxies, service meshes) require specific headers for routing, tenant identification, or policy enforcement, resulting in errors like 421 Misdirected Request or misrouting.

Solution

CLI flag: --sync-provider-headers="Key=Value,Key2=Value2" injects headers into sync requests.

Per-source config: "headers": {"Key": "Value"} in the source JSON for fine-grained control.

Per-source values take precedence over global values for conflicting keys.

HTTP:
flagd start --sync-provider-headers="X-Gateway-Host=myhost,X-Tenant-ID=tenant1"
--sources='[{"uri":"http://my-flags.com/flags","provider":"http"}]'

GRPC:
flagd start --sources='[{"uri":"proxy-gateway-server.xyz.com", "provider":"grpc","selector":"features","headers":{"X-Routing-Target-Host":"b.flags-server.service"}}]'

Headers are sent as HTTP request headers for HTTP sync and as gRPC metadata for gRPC sync.

Scope & compatibility

Fully backward compatible, i.e. headers are optional and default to empty
No behavior change for existing configurations
Covers both HTTP and gRPC sync providers

@raflFaisal raflFaisal requested review from a team as code owners April 29, 2026 00:33
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 29, 2026

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 22c7339
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/69f29643de96760009f912ed

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 29, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the ability to specify custom headers for HTTP and gRPC sync providers, either globally via a new CLI flag and environment variable or per-source in the configuration. The implementation correctly handles header merging and application to outbound requests, including special logic for the HTTP Host header. A compilation error was identified in the unit tests where the NewHTTP function is called with an incorrect number of arguments.

Comment thread core/pkg/sync/http/http_sync_test.go
Add --sync-provider-headers CLI flag and per-source headers configuration
to inject custom HTTP headers and gRPC metadata into outbound sync requests.
This enables use cases like interop gateway routing and tenant identification.

Per-source headers take precedence over global headers for conflicting keys.

Signed-off-by: raflFaisal <faisal.rafi.mca@gmail.com>
@raflFaisal raflFaisal force-pushed the feat/sync-provider-headers branch from e6b2f35 to 4a0d2e0 Compare April 29, 2026 14:06
Signed-off-by: faisal.rafi <faisal.rafi.mca@gmail.com>
Signed-off-by: faisal.rafi <faisal.rafi.mca@gmail.com>
Removed an empty line for cleaner code.

Signed-off-by: faisal.rafi <faisal.rafi.mca@gmail.com>
Signed-off-by: faisal.rafi <faisal.rafi.mca@gmail.com>
Signed-off-by: faisal.rafi <faisal.rafi.mca@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@raflFaisal raflFaisal closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant