Skip to content

Conversation

@erka
Copy link
Contributor

@erka erka commented Oct 25, 2025

This PR

Add WithHTTPClient option to both provider and transport layers to allow
users to configure custom HTTP clients. This enables use cases like custom
timeouts, proxies, or other HTTP client customizations. The option defaults
to http.DefaultClient when not specified.

…ration

Add WithHTTPClient option to both provider and transport layers to allow
users to configure custom HTTP clients. This enables use cases like custom
timeouts, proxies, or other HTTP client customizations. The option defaults
to http.DefaultClient when not specified.

Signed-off-by: Roman Dmytrenko <[email protected]>
@erka erka requested review from a team as code owners October 25, 2025 16:34
@github-actions github-actions bot requested a review from markphelps October 25, 2025 16:34
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @erka, 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 Flipt provider by introducing the capability for users to supply a custom HTTP client. This feature provides greater flexibility for integrating the provider into diverse network environments, supporting advanced configurations like custom timeouts or proxy settings. The change ensures that if no custom client is provided, the standard http.DefaultClient is utilized, maintaining backward compatibility.

Highlights

  • Custom HTTP Client Support: Introduced a new WithHTTPClient option for the Flipt provider, allowing users to supply a custom http.Client instance for more granular control over HTTP communication, such as setting custom timeouts or proxy configurations.
  • Transport Layer Integration: The custom HTTP client provided at the provider level is now seamlessly propagated down to the underlying transport layer, ensuring consistent behavior across the entire communication stack.
  • Default Client Behavior: If no custom HTTP client is specified, the provider and transport layers will default to using http.DefaultClient, maintaining existing functionality without requiring changes for current users.
  • Dependency Updates: Updated several Go module dependencies, including github.com/open-feature/go-sdk, go.uber.org/mock, and golang.org/x/text, to their latest versions.
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 introduces the WithHTTPClient option to the Flipt provider and transport layers, enabling users to configure custom HTTP clients for use cases like custom timeouts and proxies. The option defaults to http.DefaultClient when not specified. The changes include modifications to go.sum, provider.go, provider_test.go, service.go, and service_test.go to incorporate the new option and its associated functionality. I have provided review comments to address a potential issue with concurrent access to the HTTP client in the transport service.

once sync.Once
tokenProvider sdk.ClientTokenProvider
grpcDialOptions []grpc.DialOption
httpClient *http.Client
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The httpClient field in the Service struct is not protected by a mutex. If multiple goroutines access the Service concurrently, they could potentially modify the httpClient simultaneously, leading to a race condition. To prevent this, consider adding a mutex to protect access to the httpClient field.

type Service struct {
    // ... other fields
    httpClient        *http.Client
    httpClientMutex   sync.RWMutex // Add this mutex
}

Then, use the mutex to protect access to the httpClient in the WithHTTPClient option and the instance method.

Comment on lines +51 to +53
func WithHTTPClient(client *http.Client) Option {
return func(s *Service) {
s.httpClient = client
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To ensure thread-safe access to the httpClient, acquire a write lock on the httpClientMutex before modifying the httpClient and release it afterwards.

Consider the following code suggestion to address this issue.

func WithHTTPClient(client *http.Client) Option {
	return func(s *Service) {
		// Acquire a write lock before modifying the httpClient.
		// Release the lock after the modification is complete.
		// This ensures that only one goroutine can modify the httpClient at a time.
		// Prevents race conditions.
		 s.httpClientMutex.Lock()
		 s.httpClient = client
		 s.httpClientMutex.Unlock()
	}
}

}

hclient := sdk.New(sdkhttp.NewTransport(s.address), opts...)
hclient := sdk.New(sdkhttp.NewTransport(s.address, sdkhttp.WithHTTPClient(s.httpClient)), opts...)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To ensure thread-safe access to the httpClient, acquire a read lock on the httpClientMutex before accessing the httpClient and release it afterwards.

Consider the following code suggestion to address this issue.

		// Acquire a read lock before accessing the httpClient.
		// Release the lock after the access is complete.
		// This allows multiple goroutines to read the httpClient concurrently,
		// but prevents them from modifying it while it's being read.
		 s.httpClientMutex.RLock()
		 hclient := sdk.New(sdkhttp.NewTransport(s.address, sdkhttp.WithHTTPClient(s.httpClient)), opts...)
		 s.httpClientMutex.RUnlock()
		
		if u.Scheme == "https" || u.Scheme == "http" {

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.

2 participants