Branch
Hash :
ba62ee09
Author :
Thomas de Grivel
Date :
2025-09-11T23:02:18
fix test http
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
require HTTP
HTTP
require HTTP.Request
HTTP.Request
require HTTP.Response
HTTP.Response
require Socket
Socket
require Socket.Buf
Socket.Buf
(server = Socket.listen("127.0.0.1", "57000")) ; void
void
(client = Socket.Buf.connect("127.0.0.1", "57000")) ; void
void
(server_client = Socket.accept(server)) ; void
void
Buf.write_str(client.buf_rw.w, "GET / HTTP/1.0\r\n\r\n")
(Sw) 18
req = HTTP.Request.buf_parse(server_client.buf_rw.r)
%HTTP.Request{method: GET,
body: void,
url: "/",
protocol: "HTTP/1.0",
client_addr: "",
headers: [],
cookies: [],
params: %{}}
response = %HTTP.Response{body: "Hello, KC3 HTTP test server !"}
%HTTP.Response{protocol: "HTTP/1.1",
code: (U16) 200,
message: "",
headers: [{"Content-Type", "text/html"}],
body: "Hello, KC3 HTTP test server !"}
HTTP.Response.buf_write(response, server_client.buf_rw.w, true)
(Sw) 93
client_req = %HTTP.Request{method: GET}
%HTTP.Request{method: GET,
body: ?,
url: "/",
protocol: "HTTP/1.1",
client_addr: "",
headers: [],
cookies: [],
params: %{}}
HTTP.Request.buf_write(client_req, client.buf_rw.w)
(Sw) 18
HTTP.Request.buf_parse(server_client.buf_rw.r)
%HTTP.Request{method: GET,
body: void,
url: "/",
protocol: "HTTP/1.1",
client_addr: "",
headers: [],
cookies: [],
params: %{}}
HTTP.Response.buf_write(response, server_client.buf_rw.w, true)
(Sw) 93
HTTP.Response.buf_parse(client.buf_rw.r, true)
%HTTP.Response{protocol: "HTTP/1.1",
code: (U16) 200,
message: "OK",
headers: [{"Content-Type", "text/html"},
{"Content-Length", "29"}],
body: "Hello, KC3 HTTP test server !"}
Socket.Buf.close(client)
void
Socket.Buf.close(server_client)
void
Socket.close(server)
void