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

How to add a request header to dynamic C# API client proxy / How to customize dynamic C# API client proxy? #11083

Closed
ertugrulbakidal opened this issue Dec 27, 2021 · 7 comments
Labels

Comments

@ertugrulbakidal
Copy link

ertugrulbakidal commented Dec 27, 2021

  • ABP Framework version: 5.0
  • User Interface: MVC
  • Database provider: EF Core

Hi all,
I have an ABP MVC server app and an ABP MVC client app. I'd like this MVC client application to be tenant-specific. That's why I am trying to add a request header to the client app's requests to recognize the tenant by the server app. I can do it with HttpClient but I'd like to get the benefit of "Dynamic C# API Client Proxy". Is there any way to add a request header to client proxies?

@ertugrulbakidal
Copy link
Author

Hi @maliming
No, I am not using the static proxy, but I will have a look.

@yinghongzhen
Copy link

@ertugrulbaki27 hello,Have you solved the problem?

@mehmetuken
Copy link
Contributor

#11545 (comment)

u can use this method configure your httpclient.

@yinghongzhen
Copy link

#11545 (comment)

u can use this method configure your httpclient.

thanks, but how to add the dynamic params to request header?

@ertugrulbakidal
Copy link
Author

Hello @Codeio ,
You need to replace DefaultProxyHttpClientFactory

Moreover I've done in this way.

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IProxyHttpClientFactory))]

public class CustomProxyHttpClientFactory : IProxyHttpClientFactory, ITransientDependency
{
    private readonly IHttpClientFactory _httpClientFactory;
    private IRemoteServiceConfigurationProvider _remoteServiceConfigurationProvider;
    private string _tenant;
    
    public CustomProxyHttpClientFactory(IHttpClientFactory httpClientFactory, IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
    {
        _httpClientFactory = httpClientFactory;
        _remoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
        _tenant = _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default").Result["Tenant"];

    }

    public HttpClient Create()
    {
        var client = _httpClientFactory.CreateClient();
        
        client.DefaultRequestHeaders.Add(TenantResolverConsts.DefaultTenantKey, _tenant);
        return client;
    }

    public HttpClient Create(string name)
    {
        var client = _httpClientFactory.CreateClient(name);
        client.DefaultRequestHeaders.Add(TenantResolverConsts.DefaultTenantKey, _tenant);
        return client;
    }
}

@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactive label Jun 12, 2022
@stale stale bot closed this as completed Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants