Skip to content

Commit d90af1b

Browse files
committed
HttpCompletionOptionAttribute只允许修饰方法
1 parent 85bb19c commit d90af1b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

App/Clients/IUserApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public interface IUserApi : IHttpApi
3939
ITask<byte[]> GetAsByteArrayAsync([Required] string account, CancellationToken token = default);
4040

4141
[HttpGet("api/users/{account}")]
42+
[HttpCompletionOption(HttpCompletionOption.ResponseHeadersRead)]
4243
ITask<Stream> GetAsStreamAsync([Required] string account, CancellationToken token = default);
4344

4445
[HttpGet("api/users/{account}")]

WebApiClientCore/Attributes/ActionAttributes/HttpCompletionOptionAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System.Net.Http;
1+
using System;
2+
using System.Net.Http;
23
using System.Threading.Tasks;
34

45
namespace WebApiClientCore.Attributes
56
{
67
/// <summary>
78
/// 指示请求完成选项的特性
89
/// </summary>
10+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
911
public class HttpCompletionOptionAttribute : ApiActionAttribute
1012
{
1113
/// <summary>

WebApiClientCore/Attributes/FilterAttributes/LoggingFilterAttribute.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,13 @@ public sealed async override Task OnResponseAsync(ApiResponseContext context)
121121
return null;
122122
}
123123

124-
if (context.HttpContext.CompletionOption == HttpCompletionOption.ResponseHeadersRead)
124+
if (content.IsBuffered() == true ||
125+
context.HttpContext.CompletionOption == HttpCompletionOption.ResponseContentRead)
125126
{
126-
if (content.IsBuffered() == false)
127-
{
128-
return "...";
129-
}
127+
return await content.ReadAsStringAsync().ConfigureAwait(false);
130128
}
131129

132-
return await content.ReadAsStringAsync().ConfigureAwait(false);
130+
return "...";
133131
}
134132

135133
/// <summary>

0 commit comments

Comments
 (0)