1- using System . Text ;
1+ using System . Net ;
2+ using System . Text ;
23using System . Text . Json ;
34using Sisk . Cadente ;
45
5- var host = new HttpHost ( 8080 , session => {
6+ var host = new HttpHost ( new IPEndPoint ( IPAddress . Any , 8080 ) ) ;
7+ host . ContextCreated += Host_ContextCreated ;
8+
9+ host . Start ( ) ;
10+ Thread . Sleep ( Timeout . Infinite ) ;
11+
12+ void Host_ContextCreated ( HttpHost sender , HttpHostContext session ) {
613 var request = session . Request ;
714
815 if ( request . Path == "/plaintext" ) {
1421 else {
1522 session . Response . StatusCode = 404 ;
1623 }
17- } ) ;
24+ }
1825
19- host . Start ( ) ;
20- Thread . Sleep ( Timeout . Infinite ) ;
26+ static void SerializePlainTextResponse ( HttpHostContext . HttpResponse response ) {
2127
22- static void SerializePlainTextResponse ( HttpResponse response ) {
23- var contentBytes = Encoding . UTF8 . GetBytes ( "Hello, world!" ) ;
28+ var messageBytes = Encoding . UTF8 . GetBytes ( "Hello, world!" ) ;
2429
2530 response . Headers . Add ( new HttpHeader ( "Content-Type" , "text/plain" ) ) ;
26- response . ResponseStream = new MemoryStream ( contentBytes ) ;
31+ response . ResponseStream = new MemoryStream ( messageBytes ) ;
2732}
2833
29- static void SerializeJsonResponse ( HttpResponse response ) {
34+ static void SerializeJsonResponse ( HttpHostContext . HttpResponse response ) {
35+
3036 var contentBytes = JsonSerializer . SerializeToUtf8Bytes ( new {
3137 message = "Hello, world!"
3238 } ) ;
3339
34- response . Headers . Add ( new HttpHeader ( "Content-Type" , "application/json; charset=utf-8 " ) ) ;
40+ response . Headers . Add ( new HttpHeader ( "Content-Type" , "application/json" ) ) ;
3541 response . ResponseStream = new MemoryStream ( contentBytes ) ;
3642}
0 commit comments