Skip to content

feat(go-feature-flag): add CustomHeaders option#831

Open
olvlvl wants to merge 2 commits intoopen-feature:mainfrom
olvlvl:olvlvl-custom-headers
Open

feat(go-feature-flag): add CustomHeaders option#831
olvlvl wants to merge 2 commits intoopen-feature:mainfrom
olvlvl:olvlvl-custom-headers

Conversation

@olvlvl
Copy link

@olvlvl olvlvl commented Feb 4, 2026

This PR

Adds support for custom headers for every HTTP request, similar to the option found on the Ruby SDK. Custom headers can be used to define a User-Agent, to prevent requests from being blocked by servers that require browser-like identification or specific device signatures.

Notes

Our WAF requires the User-Agent header to be defined. Requests to the relay-proxy are being denied because the header is not specified.

Signed-off-by: Olivier Laviale <olivier.laviale@gmail.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @olvlvl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the GoFeatureFlag provider by adding the capability to include custom HTTP headers in all requests. This feature is crucial for environments where network infrastructure, such as WAFs, mandates the presence of specific headers like User-Agent to prevent request blocking. The change provides greater flexibility and compatibility for users deploying the GoFeatureFlag SDK in diverse network setups.

Highlights

  • Custom HTTP Headers Support: Introduced a new CustomHeaders option allowing users to define arbitrary HTTP headers that will be included in all outgoing requests made by the GoFeatureFlag provider. This addresses scenarios where specific headers, like User-Agent, are required by intermediary systems such as Web Application Firewalls (WAFs).
  • Integration into API Calls: The newly added custom headers are now applied to requests made by the CollectData and ConfigurationHasChanged API methods within the goff_api.go controller, ensuring consistent header application across key communication points.
  • Comprehensive Testing: Updated unit tests for both the API controller and the main provider to include test cases for the CustomHeaders functionality, specifically verifying that a User-Agent header is correctly set and sent with requests.
Changelog
  • providers/go-feature-flag/pkg/controller/goff_api.go
    • Added CustomHeaders map[string]string field to GoFeatureFlagApiOptions struct.
    • Modified CollectData method to iterate over CustomHeaders and set them on the HTTP request.
    • Modified ConfigurationHasChanged method to iterate over CustomHeaders and set them on the HTTP request.
  • providers/go-feature-flag/pkg/controller/goff_api_test.go
    • Updated Test_CollectDataAPI test cases to include CustomHeaders in GoFeatureFlagApiOptions and assert the presence of the User-Agent header.
    • Updated Test_ConfigurationHasChanged test case to include CustomHeaders in GoFeatureFlagApiOptions and assert the presence of the User-Agent header.
  • providers/go-feature-flag/pkg/provider.go
    • Propagated CustomHeaders from ProviderOptions to GoFeatureFlagApiOptions during provider initialization.
    • Added logic to create ofrep.WithHeaderProvider options for each custom header when initializing the ofrepProvider.
  • providers/go-feature-flag/pkg/provider_options.go
    • Added CustomHeaders map[string]string field to ProviderOptions struct.
  • providers/go-feature-flag/pkg/provider_test.go
    • Added lastRequestHeader http.Header field to mockClient to capture headers for assertion.
    • Modified roundTripFunc in mockClient to clone and store the request headers.
    • Updated TestProvider_BooleanEvaluation test cases to include CustomHeaders in ProviderOptions and assert the User-Agent header on outgoing requests.
Activity
  • The pull request was opened by olvlvl with the title "feat: Add CustomHeaders option (GoFeatureFlag)".
  • The author provided a detailed description explaining the motivation for adding custom headers, referencing a similar option in the Ruby SDK, and highlighting a specific use case involving WAF requirements for the User-Agent header.
  • The changes involve modifications to the core API controller, provider options, and comprehensive test updates to support and verify the new functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 adds a CustomHeaders option to the GoFeatureFlag provider, allowing users to set custom headers for all outgoing HTTP requests. This is a valuable addition, particularly for environments with WAFs that require specific headers like User-Agent.

The implementation is sound and well-tested. I've included a couple of suggestions to improve code clarity and reduce duplication. One suggestion is to refactor duplicated header-setting logic into a helper function in goff_api.go. Another is to simplify the code in provider.go by using the existing ofrep.WithHeader helper function.

Overall, this is a great contribution that enhances the provider's flexibility.

@erka erka changed the title feat: Add CustomHeaders option (GoFeatureFlag) feat(go-feature-flag): add CustomHeaders option Feb 4, 2026
Signed-off-by: Olivier Laviale <olivier.laviale@gmail.com>
@olvlvl olvlvl force-pushed the olvlvl-custom-headers branch from f74c2c3 to bddb297 Compare February 4, 2026 21:51
@erka
Copy link
Member

erka commented Feb 4, 2026

/gemini review

Copy link
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 a valuable feature by allowing custom headers to be set for HTTP requests, which is particularly useful for scenarios requiring a User-Agent. The implementation is solid and includes corresponding test updates. My review includes a suggestion to address an inconsistency in how the Authorization header precedence is handled between different parts of the provider. Making this change will lead to more predictable and flexible behavior. Overall, great work on this enhancement.

Copy link
Member

@erka erka left a comment

Choose a reason for hiding this comment

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

Thank you @olvlvl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants