simply json unwrappign
This commit is contained in:
parent
87aa4ed23d
commit
7af826ea13
|
@ -86,7 +86,7 @@ fn handle_req(arg: nullable *opaque) void = {
|
|||
|
||||
match (route_request(&buf, serv_req)) {
|
||||
case void => void;
|
||||
case badrequest => handle_badrequest(&buf, serv_req);
|
||||
case badrequest => handle_badrequest(serv_req);
|
||||
case notfound => handle_notfound(&buf, serv_req);
|
||||
};
|
||||
};
|
||||
|
@ -186,12 +186,12 @@ fn handle_notfound(buf: *io::stream, request: *http::server_request) void = {
|
|||
)!;
|
||||
};
|
||||
|
||||
fn handle_badrequest(buf: *io::stream, request: *http::server_request) void = {
|
||||
fn handle_badrequest(request: *http::server_request) void = {
|
||||
http::response_write(
|
||||
request.socket,
|
||||
http::STATUS_BAD_REQUEST,
|
||||
buf,
|
||||
("Content-Type", "text/plain")
|
||||
void,
|
||||
("Content-Length", "0")
|
||||
)!;
|
||||
};
|
||||
|
||||
|
@ -220,21 +220,20 @@ fn handle_cors(buf: *io::stream, serv_req: *http::server_request) void = {
|
|||
)!;
|
||||
};
|
||||
|
||||
fn json_wrap(res: (*json::value | void)) (*json::value | badrequest) = {
|
||||
return match (res) {
|
||||
case let payload: *json::value => return payload;
|
||||
case void => return badrequest;
|
||||
};
|
||||
};
|
||||
|
||||
fn handle_exec(buf: *io::stream, serv_req: *http::server_request) (void | badrequest) = {
|
||||
let request = serv_req.request;
|
||||
|
||||
let payload = match (request.body) {
|
||||
case void =>
|
||||
http::response_write(
|
||||
serv_req.socket,
|
||||
http::STATUS_BAD_REQUEST,
|
||||
void,
|
||||
("Content-Length", "0")
|
||||
)!;
|
||||
return;
|
||||
case void => return badrequest;
|
||||
case let body: io::handle =>
|
||||
let payload = json::load(body)!;
|
||||
// defer json::finish(payload);
|
||||
yield payload;
|
||||
};
|
||||
|
||||
|
@ -245,20 +244,14 @@ fn handle_exec(buf: *io::stream, serv_req: *http::server_request) (void | badreq
|
|||
case => return badrequest;
|
||||
};
|
||||
|
||||
let files = match (json::get(&payload, "files")) {
|
||||
case void => return badrequest;
|
||||
case let j: *json::value => yield j;
|
||||
};
|
||||
let files = json_wrap(json::get(&payload, "files"))?;
|
||||
|
||||
let files = match (*files) {
|
||||
case let o: json::object => yield o;
|
||||
case => return badrequest;
|
||||
};
|
||||
|
||||
let code = match (json::get(&files, "")) {
|
||||
case void => return badrequest;
|
||||
case let j: *json::value => yield j;
|
||||
};
|
||||
let code = json_wrap(json::get(&files, ""))?;
|
||||
|
||||
let code = match (*code) {
|
||||
case let c: str => yield c;
|
||||
|
|
Loading…
Reference in a new issue