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 } pop
this this
} }
full-read { this | with this ; read { this | with this ;
this:read-head:parse-head:read-body this:read-head:parse-head:read-body
} }
writeln { this | with line this ; writeln { this | with line this ;
@ -126,7 +126,7 @@ construct net:http:server:Request {
} }
finish { | with this ; finish { | with this ;
this:wrote-body not if { this:wrote-body not if {
"" this:write-body; 0 anew this:write-body;
} }
this:stream:close; this:stream:close;
} }

View file

@ -50,8 +50,22 @@ construct Stream {
close { | with this ; close { | with this ;
this:id close-stream this:id close-stream
} }
get-peer { ip:str port:int | with this ; peer { StreamPeer | with this ;
this:id get-stream-peer 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 } (" " "hello how are you" :split):foreach
"" println "" println
use net:http:Request use net:http:Request
catch { catch {
"testing http" println; "testing http" println;
def req "data.tudbut.de" 80 "GET" "/spltest" Request:new =req 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 def server "0.0.0.0" 4076 net:http:Server:new =server
{ | { |
while { 1 } { while { 1 } {
server:accept:full-read server
dup:head-str println; :accept
:read
:write-ok :write-ok
:write-str-body<"Hello! This was written to HTTP!"> :write-str-body<"Hello! This was written to HTTP!">
:finish :finish
@ -229,6 +230,8 @@ func main { int | with args ;
def req "localhost" 4076 "GET" "/spltest" Request:new =req def req "localhost" 4076 "GET" "/spltest" Request:new =req
req:send:body _str println; req:send:body _str println;
5 :foreach<{ | "" println }>
"you now have a chance to connect too: localhost :4075 :4076 - stopping in 5 seconds..." println; "you now have a chance to connect too: localhost :4075 :4076 - stopping in 5 seconds..." println;
5000 time:sleep; 5000 time:sleep;