Skip to content
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

[🚀 Feature]: [dotnet] Expose HttpClient initialization in HttpCommandExecutor to make it possible for overriding #15280

Closed
nvborisenko opened this issue Feb 13, 2025 · 5 comments

Comments

@nvborisenko
Copy link
Member

Feature and motivation

HttpCommandExecutor entirely closed for any overriding to create HttpClient:

private HttpClient CreateHttpClient()

It will be good to make it protected virtual. Proposed API:

protected virtual HttpClientHandler CreateHttpClientHandler()
protected virtual HttpClient CreateHttpClient()

It also exposes initialization of HttpClientHandler to make it possible to customize it, like ignoring certificate validation (appium/dotnet-client#455).

Usage example

class MyHttpCommandExecutor : HttpCommandExecutor
{
  override CreateHttpClientHandler()
  {
    var handler = base.CreateHttpClientHandler();
    handler.SomeProperty = "abc";
    return handler;
  }
}
Copy link

@nvborisenko, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@nvborisenko
Copy link
Member Author

It will be amazing to implement it and include into upcoming release for our Appium friends. @RenderMichael do you have any objections about proposed API?

@RenderMichael
Copy link
Contributor

I think the goal is a good one.

An alternative API would be to modify the existing HttpClient and HttpClientHandler:

public class MyHttpCommandExecutor : HttpCommandExecutor
{
  protected override void ModifyHttpClientHandler(HttpClientHandler handler)
  {
    httpHandler.ServerCertificateCustomValidationCallback = 
        HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
  }

  protected override void ModifyHttpClient(HttpClient client)
  {
    // anything else here
  }
}

This helps ensure nobody misses calling var handler = base.CreateHttpClientHandler();, prevents any null returns, and leaves things in a safer state overall.

@nvborisenko
Copy link
Member Author

ModifyHttpClientHandler wants to be an Action, like ConfigureServices(container). I prefer more Create*, then user is able to return new * he wants, not only modified. So more flexibility for advanced users.

@nvborisenko
Copy link
Member Author

Done, thanks team.

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

No branches or pull requests

2 participants