allow servers to know who their client is

This commit is contained in:
Daniella 2024-09-12 19:18:20 +02:00
parent 89d14146be
commit d4dc588c35
3 changed files with 24 additions and 7 deletions

View file

@ -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;
}

View file

@ -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
}
}

View file

@ -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;