handle request in function
This commit is contained in:
parent
cf699ad928
commit
fc2f0d0dd2
|
@ -79,7 +79,7 @@ fn handle_req(arg: nullable *opaque) void = {
|
|||
switch (request.method) {
|
||||
case "GET" =>
|
||||
switch (request.target.path) {
|
||||
case "/" => handle_index(&buf, &serv_req.request);
|
||||
case "/" => handle_index(&buf, serv_req);
|
||||
case =>
|
||||
handle_notfound(&buf, serv_req);
|
||||
return;
|
||||
|
@ -98,13 +98,6 @@ fn handle_req(arg: nullable *opaque) void = {
|
|||
handle_notfound(&buf, serv_req);
|
||||
return;
|
||||
};
|
||||
|
||||
http::response_write(
|
||||
serv_req.socket,
|
||||
http::STATUS_OK,
|
||||
&buf,
|
||||
("Content-Type", "text/plain")
|
||||
)!;
|
||||
};
|
||||
|
||||
export fn handle_notfound(buf: *io::stream, request: *http::server_request) void = {
|
||||
|
@ -172,7 +165,9 @@ export fn handle_exec(buf: *io::stream, serv_req: *http::server_request) void =
|
|||
)!;
|
||||
};
|
||||
|
||||
export fn handle_index(buf: *io::stream, request: *http::request) void = {
|
||||
export fn handle_index(buf: *io::stream, serv_req: *http::server_request) void = {
|
||||
let request = serv_req.request;
|
||||
|
||||
fmt::fprintfln(buf, "Method: {}", request.method)!;
|
||||
fmt::fprintfln(buf, "Path: {}", request.target.path)!;
|
||||
fmt::fprintfln(buf, "Fragment: {}", request.target.fragment)!;
|
||||
|
@ -196,4 +191,11 @@ export fn handle_index(buf: *io::stream, request: *http::request) void = {
|
|||
};
|
||||
fmt::fprintfln(buf, "EOF")!;
|
||||
};
|
||||
|
||||
http::response_write(
|
||||
serv_req.socket,
|
||||
http::STATUS_OK,
|
||||
buf,
|
||||
("Content-Type", "text/plain")
|
||||
)!;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue