-// http stuff {{{
-
-pub fn redirect(req: *std.http.Server.Request, location: []const u8) !void {
- try req.respond("", .{ .status = .see_other, .extra_headers = &.{.{ .name = "Location", .value = location }} });
-}
-
-pub fn get_body(req: *std.http.Server.Request) []const u8 {
- return req.server.read_buffer[req.head_end .. req.head_end + (req.head.content_length orelse 0)];
-}
-
-pub fn get_value(req: *std.http.Server.Request, name: []const u8) ?[]const u8 {
- const body = get_body(req);
- if (std.mem.indexOf(u8, body, name)) |name_index| {
- if (std.mem.indexOfScalarPos(u8, body, name_index, '=')) |eql_index| {
- if (std.mem.indexOfScalarPos(u8, body, name_index, '&')) |amp_index| {
- return body[eql_index + 1 .. amp_index];
- }
-
- return body[eql_index + 1 .. body.len];
- }
- }
- return null;
-}
-
-pub fn get_cookie(req: *std.http.Server.Request, name: []const u8) ?CookieValue {
- var header_it = req.iterateHeaders();
- while (header_it.next()) |header| {
- if (std.mem.eql(u8, header.name, "Cookie")) {
- if (std.mem.indexOf(u8, header.value, name)) |name_index| {
- if (std.mem.indexOfScalarPos(u8, header.value, name_index, '=')) |eql_index| {
- if (std.mem.indexOfPos(u8, header.value, name_index, "; ")) |semi_index| {
- return CookieValue.fromSlice(header.value[eql_index + 1 .. semi_index]) catch null;
- }
-
- return CookieValue.fromSlice(header.value[eql_index + 1 .. header.value.len]) catch null;
- }
- }
- }
- }
- return null;
-}
-
-// }}}
-