Skip to content

Commit 0cdcf86

Browse files
committed
fixed:http date header
1 parent aed939e commit 0cdcf86

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

frameworks/CSharp/touchsocket/benchmark_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"framework": "touchsocket",
33
"tests": [
44
{
5-
"default": {
5+
"webapi": {
66
"plaintext_url": "/plaintext",
77
"json_url": "/json",
88
"port": 8080,
99
"approach": "Realistic",
10-
"classification": "Platform",
10+
"classification": "Fullstack",
1111
"framework": "touchsocket.webapi",
1212
"language": "C#",
1313
"orm": "Raw",

frameworks/CSharp/touchsocket/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[framework]
22
name = "touchsocket"
33

4-
[main]
4+
[webapi]
55
urls.plaintext = "/plaintext"
66
urls.json = "/json"
77
approach = "Realistic"
@@ -18,7 +18,7 @@ versus = "aspcore-mvc"
1818
urls.plaintext = "/plaintext"
1919
urls.json = "/json"
2020
approach = "Realistic"
21-
classification = "Platform"
21+
classification = "Micro"
2222
database = "Postgres"
2323
database_os = "Linux"
2424
os = "Linux"

frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using TouchSocket.Core;
33
using TouchSocket.Http;
44
using TouchSocket.Sockets;
5+
using static System.Net.Mime.MediaTypeNames;
56
using HttpContent = TouchSocket.Http.HttpContent;
67

78
namespace TouchSocketHttp;
@@ -12,6 +13,7 @@ static async Task Main(string[] args)
1213
{
1314
int port = 8080;
1415

16+
Console.WriteLine(DateHelper.DateString);
1517
var service = new MyHttpService();
1618

1719
await service.SetupAsync(new TouchSocketConfig()
@@ -43,8 +45,8 @@ protected override MyHttpSessionClient NewClient()
4345

4446
sealed class MyHttpSessionClient : HttpSessionClient
4547
{
46-
private HttpContent m_contentPlaintext = StringHttpContent.FromText("Hello, World!");
47-
private HttpContent m_contentJson = StringHttpContent.FromJson("{\"Message\":\"Hello, World!\"}");
48+
private readonly HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
49+
private readonly HttpContent m_contentJson = new StringHttpContent("{\"message\":\"Hello, World!\"}", Encoding.UTF8, $"application/json");
4850

4951
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5052
{
@@ -57,7 +59,8 @@ protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5759
{
5860
response.StatusCode = 200;
5961
response.StatusMessage = "success";
60-
response.Headers.Add(HttpHeaders.Server, HttpExtensions.HttpHeadersServer);
62+
response.Headers.Add(HttpHeaders.Server, "T");
63+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
6164
response.Content = m_contentPlaintext;
6265
await response.AnswerAsync().ConfigureAwait(false);
6366
}
@@ -66,7 +69,8 @@ protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
6669
{
6770
response.StatusCode = 200;
6871
response.StatusMessage = "success";
69-
response.Headers.Add(HttpHeaders.Server, HttpExtensions.HttpHeadersServer);
72+
response.Headers.Add(HttpHeaders.Server, "T");
73+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
7074
response.Content = m_contentJson;
7175
await response.AnswerAsync().ConfigureAwait(false);
7276
}
@@ -79,3 +83,17 @@ protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
7983
}
8084
}
8185

86+
static class DateHelper
87+
{
88+
static Timer m_timer;
89+
static DateHelper()
90+
{
91+
m_timer = new Timer((state) =>
92+
{
93+
DateString = DateTime.UtcNow.ToGMTString();
94+
}, null, 0, 1000);
95+
}
96+
97+
public static string DateString { get; private set; }
98+
}
99+

frameworks/CSharp/touchsocket/src/TouchSocketHttp/TouchSocketHttp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="TouchSocket.Http" Version="3.0.23" />
15+
<PackageReference Include="TouchSocket.Http" Version="3.0.24" />
1616
</ItemGroup>
1717
</Project>

frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using System.Text;
12
using System.Text.Json.Serialization;
23
using TouchSocket.Core;
34
using TouchSocket.Http;
45
using TouchSocket.Rpc;
56
using TouchSocket.Sockets;
67
using TouchSocket.WebApi;
78
using TouchSocket.WebApi.Swagger;
9+
using HttpContent = TouchSocket.Http.HttpContent;
810

911
namespace TouchSocketWebApi;
1012

@@ -58,13 +60,18 @@ public static void Main(string[] args)
5860

5961
public partial class ApiServer : RpcServer
6062
{
63+
private HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
64+
6165
public static MyJson MyJson { get; set; } = new MyJson() { Message = "Hello, World!" };
6266

6367
[Router("/plaintext")]
6468
[WebApi(Method = HttpMethodType.Get)]
65-
public string Plaintext()
69+
public async Task Plaintext(IWebApiCallContext callContext)
6670
{
67-
return "Hello, World!";
71+
var response= callContext.HttpContext.Response;
72+
response.SetStatus(200, "success");
73+
response.Content= m_contentPlaintext;
74+
await response.AnswerAsync();
6875
}
6976

7077
[Router("/json")]

frameworks/CSharp/touchsocket/src/TouchSocketWebApi/TouchSocketWebApi.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
15-
<PackageReference Include="TouchSocket.Hosting" Version="3.0.23" />
16-
<PackageReference Include="TouchSocket.WebApi" Version="3.0.23" />
17-
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.0.23" />
15+
<PackageReference Include="TouchSocket.Hosting" Version="3.0.24" />
16+
<PackageReference Include="TouchSocket.WebApi" Version="3.0.24" />
17+
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.0.24" />
1818
</ItemGroup>
1919
</Project>

0 commit comments

Comments
 (0)