diff --git a/spl/http/server.spl b/spl/http/server.spl index 524f216..1fd7fac 100644 --- a/spl/http/server.spl +++ b/spl/http/server.spl @@ -91,7 +91,7 @@ construct net:http:server:Request { } pop this } - full-read { this | with this ; + read { this | with this ; this:read-head:parse-head:read-body } writeln { this | with line this ; @@ -126,7 +126,7 @@ construct net:http:server:Request { } finish { | with this ; this:wrote-body not if { - "" this:write-body; + 0 anew this:write-body; } this:stream:close; } diff --git a/spl/stream.spl b/spl/stream.spl index bde247c..6df08c1 100644 --- a/spl/stream.spl +++ b/spl/stream.spl @@ -50,8 +50,22 @@ construct Stream { close { | with this ; this:id close-stream } - get-peer { ip:str port:int | with this ; - this:id get-stream-peer + peer { StreamPeer | with this ; + this:id get-stream-peer StreamPeer:new + } +} + +construct StreamPeer { + ip + port + ; + construct { this | with ip port this ; + ip this:=ip + port this:=port + this + } + _str { str | with this ; + this:ip ":" concat this:port _str concat } } diff --git a/test.spl b/test.spl index 5151e1a..d724728 100644 --- a/test.spl +++ b/test.spl @@ -119,7 +119,7 @@ func main { int | with args ; { | println } (" " "hello how are you" :split):foreach "" println - use net:http:Request + use net:http:Request catch { "testing http" println; def req "data.tudbut.de" 80 "GET" "/spltest" Request:new =req @@ -219,8 +219,9 @@ func main { int | with args ; def server "0.0.0.0" 4076 net:http:Server:new =server { | while { 1 } { - server:accept:full-read - dup:head-str println; + server + :accept + :read :write-ok :write-str-body<"Hello! This was written to HTTP!"> :finish @@ -229,6 +230,8 @@ func main { int | with args ; def req "localhost" 4076 "GET" "/spltest" Request:new =req req:send:body _str println; + 5 :foreach<{ | "" println }> + "you now have a chance to connect too: localhost :4075 :4076 - stopping in 5 seconds..." println; 5000 time:sleep;