diff --git a/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs b/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs index ddf3528aca..c18ed8126f 100644 --- a/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs +++ b/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs @@ -11,6 +11,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Volo.Abp.DependencyInjection; using Volo.Abp.DynamicProxy; +using Volo.Abp.Http.Modeling; using Volo.Abp.Json; using Volo.Abp.Threading; @@ -85,14 +86,16 @@ namespace Volo.Abp.Http.Client.DynamicProxying using (var client = _httpClientFactory.Create()) { var proxyConfig = GetProxyConfig(); - var actionApiDescription = await _apiDescriptionFinder.FindActionAsync(proxyConfig, invocation.Method); - var url = proxyConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(actionApiDescription, invocation.ArgumentsDictionary); + var action = await _apiDescriptionFinder.FindActionAsync(proxyConfig, invocation.Method); + var url = proxyConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary); - var requestMessage = new HttpRequestMessage(actionApiDescription.GetHttpMethod(), url) + var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) { - Content = RequestPayloadBuilder.BuildContent(actionApiDescription, invocation.ArgumentsDictionary, _jsonSerializer) + Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, _jsonSerializer) }; + AddHeaders(invocation, action, requestMessage); + var response = await client.SendAsync(requestMessage); if (!response.IsSuccessStatusCode) @@ -104,6 +107,18 @@ namespace Volo.Abp.Http.Client.DynamicProxying } } + private static void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage) + { + foreach (var headerParameter in action.Parameters.Where(p => p.BindingSourceId == "Header")) + { + var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter); + if (value != null) + { + requestMessage.Headers.Add(headerParameter.Name, value.ToString()); + } + } + } + private DynamicHttpClientProxyConfig GetProxyConfig() { return _options.HttpClientProxies.GetOrDefault(typeof(TService)) diff --git a/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs b/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs index f5910f63d9..5eb5eba1de 100644 --- a/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs +++ b/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using Volo.Abp.Http.Modeling; using Volo.Abp.Reflection; diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularControllerClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularControllerClientProxy_Tests.cs new file mode 100644 index 0000000000..49f441c8f2 --- /dev/null +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularControllerClientProxy_Tests.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Http.DynamicProxying +{ + public class RegularControllerClientProxy_Tests + { + //TODO: Create a regular MVC Controller and add different parameter bindings, verbs and routes and test client proxy for it! + } +}