22using TouchSocket . Core ;
33using TouchSocket . Http ;
44using TouchSocket . Sockets ;
5- using static System . Net . Mime . MediaTypeNames ;
65using HttpContent = TouchSocket . Http . HttpContent ;
76
87namespace TouchSocketHttp ;
98
109public class Program
1110{
12- static async Task Main ( string [ ] args )
11+ private static async Task Main ( string [ ] args )
1312 {
1413 int port = 8080 ;
15-
16- Console . WriteLine ( DateHelper . DateString ) ;
17- var service = new MyHttpService ( ) ;
14+ MyHttpService service = new MyHttpService ( ) ;
1815
1916 await service . SetupAsync ( new TouchSocketConfig ( )
2017 . SetListenIPHosts ( port )
2118 . SetNoDelay ( true )
19+ . SetTransportOption ( options =>
20+ {
21+ options . ReceivePipeOptions = TransportOption . CreateSchedulerOptimizedPipeOptions ( ) ;
22+ options . SendPipeOptions = TransportOption . CreateSchedulerOptimizedPipeOptions ( ) ;
23+ } )
2224 . SetMaxCount ( 1000000 )
2325 . SetBacklog ( 1000 )
2426 . ConfigureContainer ( a =>
@@ -35,42 +37,42 @@ await service.SetupAsync(new TouchSocketConfig()
3537 }
3638}
3739
38- sealed class MyHttpService : HttpService < MyHttpSessionClient >
40+ internal sealed class MyHttpService : HttpService < MyHttpSessionClient >
3941{
4042 protected override MyHttpSessionClient NewClient ( )
4143 {
4244 return new MyHttpSessionClient ( ) ;
4345 }
4446}
4547
46- sealed class MyHttpSessionClient : HttpSessionClient
48+ internal sealed class MyHttpSessionClient : HttpSessionClient
4749{
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") ;
50+ private readonly HttpContent m_contentPlaintext = new StringHttpContent ( "Hello, World!" , Encoding . UTF8 , "text/plain" ) ;
51+ private readonly HttpContent m_contentJson = new StringHttpContent ( "{\" message\" :\" Hello, World!\" }" , Encoding . UTF8 , "application/json" ) ;
5052
5153 protected override async Task OnReceivedHttpRequest ( HttpContext httpContext )
5254 {
53- var request = httpContext . Request ;
54- var response = httpContext . Response ;
55+ HttpRequest request = httpContext . Request ;
56+ HttpResponse response = httpContext . Response ;
5557
5658 switch ( request . RelativeURL )
5759 {
5860 case "/plaintext" :
5961 {
6062 response . StatusCode = 200 ;
61- response . StatusMessage = "success " ;
63+ response . StatusMessage = "ok " ;
6264 response . Headers . Add ( HttpHeaders . Server , "T" ) ;
63- response . Headers . Add ( HttpHeaders . Date , DateHelper . DateString ) ;
65+ response . Headers . Add ( HttpHeaders . Date , HttpExtensions . CurrentHttpDate ) ;
6466 response . Content = m_contentPlaintext ;
6567 await response . AnswerAsync ( ) . ConfigureAwait ( false ) ;
6668 }
6769 break ;
6870 case "/json" :
6971 {
7072 response . StatusCode = 200 ;
71- response . StatusMessage = "success " ;
73+ response . StatusMessage = "ok " ;
7274 response . Headers . Add ( HttpHeaders . Server , "T" ) ;
73- response . Headers . Add ( HttpHeaders . Date , DateHelper . DateString ) ;
75+ response . Headers . Add ( HttpHeaders . Date , HttpExtensions . CurrentHttpDate ) ;
7476 response . Content = m_contentJson ;
7577 await response . AnswerAsync ( ) . ConfigureAwait ( false ) ;
7678 }
@@ -81,19 +83,4 @@ protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
8183 break ;
8284 }
8385 }
84- }
85-
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-
86+ }
0 commit comments