Remove Body param

Yeah I just misunderstood something in the HTML spec whoops
This commit is contained in:
jaina heartles 2022-11-15 00:56:30 -08:00
parent 0b04ad5e00
commit db1bd0f7c7

View file

@ -103,7 +103,10 @@ fn parseBody(comptime T: type, content_type: BaseContentType, reader: anytype, a
return try util.deepClone(alloc, body); return try util.deepClone(alloc, body);
}, },
else => return error.UnsupportedMediaType, else => {
std.log.debug("{}", .{content_type});
return error.UnsupportedMediaType;
},
} }
} }
@ -133,8 +136,6 @@ pub fn Context(comptime Route: type) type {
// leave it as a simple string instead of void // leave it as a simple string instead of void
pub const Query = if (@hasDecl(Route, "Query")) Route.Query else void; pub const Query = if (@hasDecl(Route, "Query")) Route.Query else void;
pub const Data = if (@hasDecl(Route, "Data")) Route.Data else void;
base_request: *http.Request, base_request: *http.Request,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
@ -146,7 +147,6 @@ pub fn Context(comptime Route: type) type {
args: Args, args: Args,
body: Body, body: Body,
query: Query, query: Query,
data: Data,
// TODO // TODO
body_buf: ?[]const u8 = null, body_buf: ?[]const u8 = null,
@ -185,23 +185,9 @@ pub fn Context(comptime Route: type) type {
const path = std.mem.sliceTo(req.uri, '?'); const path = std.mem.sliceTo(req.uri, '?');
const q = req.uri[path.len..]; const q = req.uri[path.len..];
break :blk try query_utils.parseQuery(Query, q); break :blk try query_utils.parseQuery(alloc, Query, q);
}; };
defer if (Query != void) util.deepFree(alloc, query);
var should_free_data: bool = false;
const data = if (Data != void) blk: {
if (Query != void or Body != void) @compileError("Cannot specify both Data and Query/Body");
if (base_content_type == .url_encoded) {
const path = std.mem.sliceTo(req.uri, '?');
const q = req.uri[path.len..];
break :blk try query_utils.parseQuery(Query, q);
} else {
should_free_data = true;
var stream = req.body orelse return error.NoBody;
break :blk try parseBody(Body, base_content_type orelse .json, stream.reader(), alloc);
}
};
defer if (should_free_data) util.deepFree(alloc, data);
var api_conn = conn: { var api_conn = conn: {
const host = req.headers.get("Host") orelse return error.NoHost; const host = req.headers.get("Host") orelse return error.NoHost;
@ -230,7 +216,6 @@ pub fn Context(comptime Route: type) type {
.args = args, .args = args,
.body = body, .body = body,
.query = query, .query = query,
.data = data,
}; };
try Route.handler(self, res, &api_conn); try Route.handler(self, res, &api_conn);