diff --git a/.ikc3_history b/.ikc3_history
index fa20a8e..a5fac91 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -97,4 +97,3 @@ req = %HTTP.Request{headers: [{"Content-Type", "text/html"}]}
#{req}
"#{req}"
req = %HTTP.Request{headers: ["Content-Type" => "text/html"]}
-
diff --git a/http/http_response.c b/http/http_response.c
index fe4f57d..7feb726 100644
--- a/http/http_response.c
+++ b/http/http_response.c
@@ -25,7 +25,6 @@ s_http_response * http_response_buf_parse (s_http_response *response,
sw r = 0;
s_buf_save save;
s_str str;
- s_tag tag_code = {0};
s_http_response tmp = {0};
s_tuple *tuple = NULL;
s_tag *value = NULL;
@@ -34,9 +33,9 @@ s_http_response * http_response_buf_parse (s_http_response *response,
buf_save_init(buf, &save);
if (! buf_read_until_1_into_str(buf, " ", &tmp.protocol))
goto clean;
- if (! buf_parse_tag_u16(buf, &tag_code))
+ if (buf_parse_u16(buf, &tmp.code) <= 0)
goto restore;
- if (tag_code.data.u16 < 100 || tag_code.data.u16 > 999) {
+ if (tmp.code < 100 || tmp.code > 999) {
err_puts("http_response_buf_parse: invalid response code");
goto restore;
}
@@ -76,7 +75,7 @@ s_http_response * http_response_buf_parse (s_http_response *response,
goto ok;
if (content_length < 0)
goto restore;
- if (! buf_read(buf, content_length, &response->body))
+ if (! buf_read(buf, content_length, &tmp.body))
goto restore;
ok:
buf_save_clean(buf, &save);
diff --git a/http/misc/client.kc3 b/http/misc/client.kc3
new file mode 100644
index 0000000..c73489b
--- /dev/null
+++ b/http/misc/client.kc3
@@ -0,0 +1,16 @@
+quote client = Socket.Buf.connect("localhost", "58000")
+client = Socket.Buf.connect("localhost", "58000")
+quote client_req = %HTTP.Request{method: :get,
+ url: "/",
+ protocol: "HTTP/1.1",
+ headers: []}
+client_req = %HTTP.Request{method: :get,
+ url: "/",
+ protocol: "HTTP/1.1",
+ headers: []}
+quote HTTP.Request.buf_write(client_req, client.buf_rw.w)
+HTTP.Request.buf_write(client_req, client.buf_rw.w)
+quote client_response = HTTP.Response.buf_parse(client.buf_rw.r, true)
+client_response = HTTP.Response.buf_parse(client.buf_rw.r, true)
+quote Socket.Buf.close(client)
+Socket.Buf.close(client)
diff --git a/lib/kc3/0.1/http/response.kc3 b/lib/kc3/0.1/http/response.kc3
index ffcc4da..a72ca1e 100644
--- a/lib/kc3/0.1/http/response.kc3
+++ b/lib/kc3/0.1/http/response.kc3
@@ -12,6 +12,10 @@ defmodule HTTP.Response do
{(U16) 404, "Not Found"},
{(U16) 500, "Internal Server Error"}]
+ # buf_parse(buf_w, parse_body) => response
+ def buf_parse = cfn HTTP.Response "http_response_buf_parse" (Result,
+ Buf, Bool)
+
# buf_write(response, buf_w, send_body)
def buf_write = cfn Sw "http_response_buf_write" (HTTP.Response, Buf,
Bool)
diff --git a/test/http/04_server_request.kc3 b/test/http/04_server_request.kc3
index cb3048f..4c99fb4 100644
--- a/test/http/04_server_request.kc3
+++ b/test/http/04_server_request.kc3
@@ -20,20 +20,16 @@ client_req = %HTTP.Request{method: :get,
url: "/",
protocol: "HTTP/1.1",
headers: []}
-quote r = HTTP.Request.buf_write(client_req, client.buf_rw.w)
-r = HTTP.Request.buf_write(client_req, client.buf_rw.w)
-quote puts(r)
-puts(r)
-quote if (r) do
- req = HTTP.Request.buf_parse(server_client.buf_rw.r)
- puts(req)
- HTTP.Response.buf_write(response, client.buf_rw.w, true)
-end
-if (r) do
- req = HTTP.Request.buf_parse(server_client.buf_rw.r)
- puts(req)
- HTTP.Response.buf_write(response, client.buf_rw.w, true)
-end
+quote HTTP.Request.buf_write(client_req, client.buf_rw.w)
+HTTP.Request.buf_write(client_req, client.buf_rw.w)
+quote HTTP.Request.buf_parse(server_client.buf_rw.r)
+HTTP.Request.buf_parse(server_client.buf_rw.r)
+quote HTTP.Response.buf_write(response, client.buf_rw.w, true)
+HTTP.Response.buf_write(response, client.buf_rw.w, true)
+quote HTTP.Request.buf_parse(server_client.buf_rw.r)
+HTTP.Request.buf_parse(server_client.buf_rw.r)
+quote HTTP.Response.buf_write(response, client.buf_rw.w, true)
+HTTP.Response.buf_write(response, client.buf_rw.w, true)
quote Socket.Buf.close(client)
Socket.Buf.close(client)
quote Socket.Buf.close(server_client)
diff --git a/test/http/07_client_server.kc3 b/test/http/07_client_server.kc3
new file mode 100644
index 0000000..09c4219
--- /dev/null
+++ b/test/http/07_client_server.kc3
@@ -0,0 +1,32 @@
+quote server = Socket.listen("localhost", "57000")
+server = Socket.listen("localhost", "57000")
+quote client = Socket.Buf.connect("localhost", "57000")
+client = Socket.Buf.connect("localhost", "57000")
+quote server_client = Socket.Buf.accept(server)
+server_client = Socket.Buf.accept(server)
+quote client_req = %HTTP.Request{method: :get,
+ url: "/",
+ protocol: "HTTP/1.1",
+ headers: []}
+client_req = %HTTP.Request{method: :get,
+ url: "/",
+ protocol: "HTTP/1.1",
+ headers: []}
+quote HTTP.Request.buf_write(client_req, client.buf_rw.w)
+HTTP.Request.buf_write(client_req, client.buf_rw.w)
+quote req = HTTP.Request.buf_parse(server_client.buf_rw.r)
+req = HTTP.Request.buf_parse(server_client.buf_rw.r)
+quote puts(req)
+puts(req)
+quote res = HTTP.Response.buf_write(%HTTP.Response{body: "Hello !"}, server_client.buf_rw.w, true)
+res = HTTP.Response.buf_write(%HTTP.Response{body: "Hello !"}, server_client.buf_rw.w, true)
+quote client_response = HTTP.Response.buf_parse(client.buf_rw.r, true)
+client_response = HTTP.Response.buf_parse(client.buf_rw.r, true)
+quote puts(client_response)
+puts(client_response)
+quote Socket.Buf.close(server_client)
+Socket.Buf.close(server_client)
+quote Socket.Buf.close(client)
+Socket.Buf.close(client)
+quote Socket.close(server)
+Socket.close(server)
diff --git a/test/http/07_client_server.out.expected b/test/http/07_client_server.out.expected
new file mode 100644
index 0000000..1c99d97
--- /dev/null
+++ b/test/http/07_client_server.out.expected
@@ -0,0 +1,10 @@
+%HTTP.Request{method: :get,
+ url: "/",
+ protocol: "HTTP/1.1",
+ headers: []}
+%HTTP.Response{protocol: "HTTP/1.1",
+ code: (U16) 200,
+ message: "OK",
+ headers: [{"Content-Type", "text/html"},
+ {"Content-Length", "7"}],
+ body: "Hello !"}
diff --git a/test/http/07_client_server.ret.expected b/test/http/07_client_server.ret.expected
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/http/07_client_server.ret.expected
@@ -0,0 +1 @@
+0