4 changed files with 271 additions and 9 deletions
@ -0,0 +1,45 @@ |
|||||
|
# LINGYUN.Abp.Http.Client.Wrapper |
||||
|
|
||||
|
HTTP client wrapper module for automatically adding wrapper request headers in HTTP client requests. |
||||
|
|
||||
|
[简体中文](./README.md) |
||||
|
|
||||
|
## Features |
||||
|
|
||||
|
* Automatic addition of wrapper request headers |
||||
|
* Integration with ABP HTTP client |
||||
|
* Support for global wrapper configuration |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
```bash |
||||
|
dotnet add package LINGYUN.Abp.Http.Client.Wrapper |
||||
|
``` |
||||
|
|
||||
|
## Configuration |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpHttpClientWrapperModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpWrapperOptions>(options => |
||||
|
{ |
||||
|
// Enable wrapper |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## How It Works |
||||
|
|
||||
|
When the wrapper is enabled (`AbpWrapperOptions.IsEnabled = true`), the module automatically adds the `_AbpWrapResult` header to all HTTP client requests. |
||||
|
When the wrapper is disabled (`AbpWrapperOptions.IsEnabled = false`), the module automatically adds the `_AbpDontWrapResult` header to all HTTP client requests. |
||||
|
|
||||
|
This ensures that the HTTP client request results remain consistent with the server-side wrapper configuration. |
||||
|
|
||||
|
## Source Code |
||||
|
|
||||
|
[LINGYUN.Abp.Http.Client.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper) |
||||
@ -0,0 +1,45 @@ |
|||||
|
# LINGYUN.Abp.Http.Client.Wrapper |
||||
|
|
||||
|
HTTP客户端包装器模块,用于在HTTP客户端请求中自动添加包装器请求头。 |
||||
|
|
||||
|
[English](./README.EN.md) |
||||
|
|
||||
|
## 功能特性 |
||||
|
|
||||
|
* 自动添加包装器请求头 |
||||
|
* 与ABP HTTP客户端集成 |
||||
|
* 支持全局配置包装器开关 |
||||
|
|
||||
|
## 安装 |
||||
|
|
||||
|
```bash |
||||
|
dotnet add package LINGYUN.Abp.Http.Client.Wrapper |
||||
|
``` |
||||
|
|
||||
|
## 配置使用 |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpHttpClientWrapperModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpWrapperOptions>(options => |
||||
|
{ |
||||
|
// 启用包装器 |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## 工作原理 |
||||
|
|
||||
|
当启用包装器时(`AbpWrapperOptions.IsEnabled = true`),模块会自动为所有HTTP客户端请求添加 `_AbpWrapResult` 请求头。 |
||||
|
当禁用包装器时(`AbpWrapperOptions.IsEnabled = false`),模块会自动为所有HTTP客户端请求添加 `_AbpDontWrapResult` 请求头。 |
||||
|
|
||||
|
这样可以确保HTTP客户端的请求结果与服务器端的包装配置保持一致。 |
||||
|
|
||||
|
## 源码位置 |
||||
|
|
||||
|
[LINGYUN.Abp.Http.Client.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper) |
||||
@ -0,0 +1,98 @@ |
|||||
|
# LINGYUN.Abp.AspNetCore.Mvc.Wrapper |
||||
|
|
||||
|
MVC wrapper implementation module for unified wrapping of ASP.NET Core MVC response results. |
||||
|
|
||||
|
[简体中文](./README.md) |
||||
|
|
||||
|
## Features |
||||
|
|
||||
|
* Automatic wrapping of MVC response results |
||||
|
* Support for custom wrapping rules |
||||
|
* Support for exception result wrapping |
||||
|
* Support for localized error messages |
||||
|
* Support for API documentation wrapping description |
||||
|
* Support for ignoring specific controllers, namespaces, and return types |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
```bash |
||||
|
dotnet add package LINGYUN.Abp.AspNetCore.Mvc.Wrapper |
||||
|
``` |
||||
|
|
||||
|
## Configuration |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpAspNetCoreMvcWrapperModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpWrapperOptions>(options => |
||||
|
{ |
||||
|
// Enable wrapper |
||||
|
options.IsEnabled = true; |
||||
|
|
||||
|
// Ignore specific return types |
||||
|
options.IgnoreReturnTypes.Add<IRemoteStreamContent>(); |
||||
|
|
||||
|
// Ignore specific controllers |
||||
|
options.IgnoreControllers.Add<AbpApiDefinitionController>(); |
||||
|
|
||||
|
// Ignore specific URL prefixes |
||||
|
options.IgnorePrefixUrls.Add("/connect"); |
||||
|
|
||||
|
// Custom empty result message |
||||
|
options.MessageWithEmptyResult = (serviceProvider) => |
||||
|
{ |
||||
|
var localizer = serviceProvider.GetRequiredService<IStringLocalizer<AbpMvcWrapperResource>>(); |
||||
|
return localizer["Wrapper:NotFound"]; |
||||
|
}; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## Configuration Options |
||||
|
|
||||
|
* `IsEnabled`: Whether to enable the wrapper |
||||
|
* `IsWrapUnauthorizedEnabled`: Whether to wrap unauthorized responses |
||||
|
* `HttpStatusCode`: HTTP status code for wrapped responses |
||||
|
* `IgnoreReturnTypes`: List of return types to ignore wrapping |
||||
|
* `IgnoreControllers`: List of controllers to ignore wrapping |
||||
|
* `IgnoreNamespaces`: List of namespaces to ignore wrapping |
||||
|
* `IgnorePrefixUrls`: List of URL prefixes to ignore wrapping |
||||
|
* `IgnoreExceptions`: List of exception types to ignore wrapping |
||||
|
* `ErrorWithEmptyResult`: Whether to return error message for empty results |
||||
|
* `CodeWithEmptyResult`: Error code for empty results |
||||
|
* `MessageWithEmptyResult`: Error message for empty results |
||||
|
* `CodeWithSuccess`: Code for successful responses |
||||
|
|
||||
|
## Advanced Usage |
||||
|
|
||||
|
### 1. Using Attributes to Ignore Wrapping |
||||
|
|
||||
|
```csharp |
||||
|
[IgnoreWrapResult] |
||||
|
public class TestController : AbpController |
||||
|
{ |
||||
|
// All actions in this controller will not be wrapped |
||||
|
} |
||||
|
|
||||
|
public class TestController : AbpController |
||||
|
{ |
||||
|
[IgnoreWrapResult] |
||||
|
public IActionResult Test() |
||||
|
{ |
||||
|
// This action will not be wrapped |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
### 2. Controlling Wrapping via Request Headers |
||||
|
|
||||
|
* Add `_AbpDontWrapResult` header to disable wrapping |
||||
|
* Add `_AbpWrapResult` header to force enable wrapping |
||||
|
|
||||
|
## Source Code |
||||
|
|
||||
|
[LINGYUN.Abp.AspNetCore.Mvc.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper) |
||||
Loading…
Reference in new issue