Enis Necipoglu
1 year ago
No known key found for this signature in database
GPG Key ID: 1EC55E13241E1680
9 changed files with
70 additions and
5 deletions
-
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs
-
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientOptions.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs
-
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs
-
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs
-
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs
-
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs
|
|
|
@ -191,7 +191,9 @@ public class AuditingInterceptor : AbpInterceptor, ITransientDependency |
|
|
|
} |
|
|
|
|
|
|
|
if (!options.IsEnabledForGetRequests && |
|
|
|
invocation.Method.Name.StartsWith("Get", StringComparison.OrdinalIgnoreCase)) |
|
|
|
(string.Equals(auditLogInfo.HttpMethod, "Get", StringComparison.OrdinalIgnoreCase) || |
|
|
|
string.Equals(auditLogInfo.HttpMethod, "Head", StringComparison.OrdinalIgnoreCase) || |
|
|
|
invocation.Method.Name.StartsWith("Get", StringComparison.OrdinalIgnoreCase))) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
@ -132,7 +132,13 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB |
|
|
|
Serialize(eventData), |
|
|
|
Clock.Now |
|
|
|
); |
|
|
|
outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()!); |
|
|
|
|
|
|
|
var correlationId = CorrelationIdProvider.Get(); |
|
|
|
if (correlationId != null) |
|
|
|
{ |
|
|
|
outgoingEventInfo.SetCorrelationId(correlationId); |
|
|
|
} |
|
|
|
|
|
|
|
await eventOutbox.EnqueueAsync(outgoingEventInfo); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,5 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Net.Http; |
|
|
|
using Volo.Abp.Http.Client.ClientProxying; |
|
|
|
using Volo.Abp.Http.Client.Proxying; |
|
|
|
|
|
|
|
namespace Volo.Abp.Http.Client; |
|
|
|
@ -8,8 +10,17 @@ public class AbpHttpClientOptions |
|
|
|
{ |
|
|
|
public Dictionary<Type, HttpClientProxyConfig> HttpClientProxies { get; set; } |
|
|
|
|
|
|
|
public Dictionary<string, List<Action<HttpClientProxyConfig, ClientProxyRequestContext, HttpClient>>> ProxyHttpClientPreSendActions { get; } |
|
|
|
|
|
|
|
public AbpHttpClientOptions() |
|
|
|
{ |
|
|
|
HttpClientProxies = new Dictionary<Type, HttpClientProxyConfig>(); |
|
|
|
ProxyHttpClientPreSendActions = new Dictionary<string, List<Action<HttpClientProxyConfig, ClientProxyRequestContext, HttpClient>>>(); |
|
|
|
} |
|
|
|
|
|
|
|
public AbpHttpClientOptions AddPreSendAction(string remoteServiceName, Action<HttpClientProxyConfig, ClientProxyRequestContext, HttpClient> action) |
|
|
|
{ |
|
|
|
ProxyHttpClientPreSendActions.GetOrAdd(remoteServiceName, () => new List<Action<HttpClientProxyConfig, ClientProxyRequestContext, HttpClient>>()).Add(action); |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -146,6 +146,11 @@ public class ClientProxyBase<TService> : ITransientDependency |
|
|
|
HttpResponseMessage response; |
|
|
|
try |
|
|
|
{ |
|
|
|
foreach (var preSendAction in ClientOptions.Value.ProxyHttpClientPreSendActions.Where(x => x.Key == clientConfig.RemoteServiceName).SelectMany(x => x.Value)) |
|
|
|
{ |
|
|
|
preSendAction(clientConfig, requestContext, client); |
|
|
|
} |
|
|
|
|
|
|
|
response = await client.SendAsync( |
|
|
|
requestMessage, |
|
|
|
HttpCompletionOption.ResponseHeadersRead /*this will buffer only the headers, the content will be used as a stream*/, |
|
|
|
@ -309,7 +314,11 @@ public class ClientProxyBase<TService> : ITransientDependency |
|
|
|
} |
|
|
|
|
|
|
|
//CorrelationId
|
|
|
|
requestMessage.Headers.Add(AbpCorrelationIdOptions.Value.HttpHeaderName, CorrelationIdProvider.Get()); |
|
|
|
var correlationId = CorrelationIdProvider.Get(); |
|
|
|
if (correlationId != null) |
|
|
|
{ |
|
|
|
requestMessage.Headers.Add(AbpCorrelationIdOptions.Value.HttpHeaderName, correlationId); |
|
|
|
} |
|
|
|
|
|
|
|
//TenantId
|
|
|
|
if (CurrentTenant.Id.HasValue) |
|
|
|
|
|
|
|
@ -126,7 +126,11 @@ public class ApiDescriptionFinder : IApiDescriptionFinder, ITransientDependency |
|
|
|
protected virtual void AddHeaders(HttpRequestMessage requestMessage) |
|
|
|
{ |
|
|
|
//CorrelationId
|
|
|
|
requestMessage.Headers.Add(AbpCorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get()); |
|
|
|
var correlationId = CorrelationIdProvider.Get(); |
|
|
|
if (correlationId != null) |
|
|
|
{ |
|
|
|
requestMessage.Headers.Add(AbpCorrelationIdOptions.HttpHeaderName, correlationId); |
|
|
|
} |
|
|
|
|
|
|
|
//TenantId
|
|
|
|
if (CurrentTenant.Id.HasValue) |
|
|
|
|
|
|
|
@ -1,8 +1,11 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Net.Http; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
|
using Volo.Abp.Http.Client; |
|
|
|
using Volo.Abp.Http.Client.ClientProxying; |
|
|
|
using Volo.Abp.Http.Client.Proxying; |
|
|
|
using Volo.Abp.Http.DynamicProxying; |
|
|
|
using Volo.Abp.Http.Localization; |
|
|
|
using Volo.Abp.Localization; |
|
|
|
@ -60,5 +63,16 @@ public class AbpHttpClientTestModule : AbpModule |
|
|
|
options.FormDataConverts.Add(typeof(List<GetParamsNameValue>), typeof(TestObjectToFormData)); |
|
|
|
options.PathConverts.Add(typeof(int), typeof(TestObjectToPath)); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpHttpClientOptions>(options => |
|
|
|
{ |
|
|
|
options.AddPreSendAction("Default", (_, requestContext, httpclient) => |
|
|
|
{ |
|
|
|
if (requestContext.Action.Name.Equals("TimeOutRequestAsync")) |
|
|
|
{ |
|
|
|
httpclient.Timeout = TimeSpan.FromMilliseconds(1); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -43,4 +43,7 @@ public interface IRegularTestController |
|
|
|
Task<int> DeleteByIdAsync(int id); |
|
|
|
|
|
|
|
Task<string> AbortRequestAsync(CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task<string> TimeOutRequestAsync(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ -152,6 +152,14 @@ public class RegularTestController : AbpController, IRegularTestController |
|
|
|
await Task.Delay(100, cancellationToken); |
|
|
|
return "AbortRequestAsync"; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("timeout-request")] |
|
|
|
public async Task<string> TimeOutRequestAsync() |
|
|
|
{ |
|
|
|
await Task.Delay(100); |
|
|
|
return "TimeOutRequestAsync"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class Car |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
@ -187,4 +188,11 @@ public class RegularTestControllerClientProxy_Tests : AbpHttpClientTestBase |
|
|
|
var exception = await Assert.ThrowsAsync<AbpRemoteCallException>(async () => await _controller.AbortRequestAsync(cts.Token)); |
|
|
|
exception.InnerException.InnerException.InnerException.Message.ShouldBe("The client aborted the request."); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task TimeOutRequestAsync() |
|
|
|
{ |
|
|
|
var exception = await Assert.ThrowsAsync<HttpRequestException>(async () => await _controller.TimeOutRequestAsync()); |
|
|
|
exception.InnerException.InnerException.Message.ShouldBe("The client aborted the request."); |
|
|
|
} |
|
|
|
} |
|
|
|
|