1717 */
1818
1919using System ;
20- using System . Diagnostics ;
21- using System . IO . Ports ;
22- using System . Net ;
2320using System . Net . Sockets ;
2421using uhttpsharp ;
22+ using uhttpsharp . Handlers ;
23+ using uhttpsharpdemo . Handlers ;
2524
2625namespace uhttpsharpdemo
2726{
2827 internal static class Program
2928 {
3029 private static void Main ( )
3130 {
32- for ( var port = 8000 ; port <= 65535 ; ++ port )
33- {
34- var httpServer = new HttpServer ( port ) ;
35-
36- httpServer . Use ( new TimingHandler ( ) ) ;
37- httpServer . Use ( new HttpRouter ( ) . With ( string . Empty , new IndexHandler ( ) )
38- . With ( "about" , new AboutHandler ( ) ) ) ;
39- httpServer . Use ( new FileHandler ( ) ) ;
40- httpServer . Use ( new ErrorHandler ( ) ) ;
31+ log4net . Config . XmlConfigurator . Configure ( ) ;
4132
42- try
43- {
44- httpServer . Start ( ) ;
45- }
46- catch ( SocketException )
33+ for ( var port = 8000 ; port <= 65535 ; port ++ )
34+ {
35+ using ( var httpServer = new HttpServer ( port , new HttpRequestProvider ( ) ) )
4736 {
48- continue ;
37+ httpServer . Use ( new TimingHandler ( ) ) ;
38+ httpServer . Use ( new HttpRouter ( ) . With ( string . Empty , new IndexHandler ( ) )
39+ . With ( "about" , new AboutHandler ( ) ) ) ;
40+ httpServer . Use ( new FileHandler ( ) ) ;
41+ httpServer . Use ( new ErrorHandler ( ) ) ;
42+
43+ try
44+ {
45+ httpServer . Start ( ) ;
46+ Console . ReadLine ( ) ;
47+ }
48+ catch ( SocketException )
49+ {
50+ continue ;
51+ }
4952 }
50- break ;
53+ return ;
5154 }
52- Console . ReadLine ( ) ;
53- }
54- }
55-
56- public class TimingHandler : IHttpRequestHandler
57- {
58-
59- public async System . Threading . Tasks . Task < HttpResponse > Handle ( HttpRequest httpRequest , Func < System . Threading . Tasks . Task < HttpResponse > > next )
60- {
61- var stopWatch = Stopwatch . StartNew ( ) ;
62- var retVal = await next ( ) ;
63- Console . WriteLine ( stopWatch . Elapsed ) ;
64- return retVal ;
6555 }
6656 }
6757}
0 commit comments