mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
This commit is contained in:
parent
2d8ca92143
commit
c7b79f144a
@ -3,12 +3,12 @@
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.zmd = .{
|
||||
.url = "https://github.com/jetzig-framework/zmd/archive/6dda080c7fcbe78c39d9e4f52b8eec9aa7cbbaad.tar.gz",
|
||||
.hash = "12208a01a7c10d0583f253787cf7271587d9509862f34e2b6d754cade7bc08500ef6",
|
||||
.url = "https://github.com/jetzig-framework/zmd/archive/d6c8aa9a9cde99674ccb096d8f94ed09cba8dab.tar.gz",
|
||||
.hash = "1220d0e8734628fd910a73146e804d10a3269e3e7d065de6bb0e3e88d5ba234eb163",
|
||||
},
|
||||
.zmpl = .{
|
||||
.url = "https://github.com/jetzig-framework/zmpl/archive/a128d0a9c9cd70ca9f007405ae3d17e3a074ab34.tar.gz",
|
||||
.hash = "1220e1e95a5479b24e1c5448c5dc4ad283a01050617d0e5d9ff1c7e7283c639df24a",
|
||||
.url = "https://github.com/jetzig-framework/zmpl/archive/dc3ed9dd695328fba0643635644089bc79307cc0.tar.gz",
|
||||
.hash = "1220e23465d94b00a8c4b2abd4d2c433c7e8a942d779e83cab9eb6c207252373308b",
|
||||
},
|
||||
.jetkv = .{
|
||||
.url = "https://github.com/jetzig-framework/jetkv/archive/2b1130a48979ea2871c8cf6ca89c38b1e7062839.tar.gz",
|
||||
|
@ -68,7 +68,7 @@ test "json from header" {
|
||||
const response = try app.request(
|
||||
.GET,
|
||||
"/",
|
||||
.{ .headers = &.{.{ .name = "accept", .value = "application/json" }} },
|
||||
.{ .headers = .{ .accept = "application/json" } },
|
||||
);
|
||||
try response.expectJson(".message", "Welcome to Jetzig!");
|
||||
try response.expectJson(".custom_number", 600);
|
||||
|
@ -70,7 +70,7 @@ pub fn append(self: *Headers, name: []const u8, value: []const u8) !void {
|
||||
var buf: [max_bytes_header_name]u8 = undefined;
|
||||
const lower = std.ascii.lowerString(&buf, name);
|
||||
|
||||
const header = .{
|
||||
const header = Header{
|
||||
.name = try self.allocator.dupe(u8, lower),
|
||||
.value = try self.allocator.dupe(u8, value),
|
||||
};
|
||||
|
@ -221,7 +221,7 @@ pub fn renderRedirect(self: *Request, state: RedirectState) !void {
|
||||
}
|
||||
};
|
||||
|
||||
const view = .{ .data = self.response_data, .status_code = state.status_code };
|
||||
const view = jetzig.views.View{ .data = self.response_data, .status_code = state.status_code };
|
||||
const status = jetzig.http.status_codes.get(state.status_code);
|
||||
const maybe_template = jetzig.zmpl.findPrefixed("views", status.getCode());
|
||||
self.rendered_view = view;
|
||||
|
@ -80,9 +80,9 @@ pub fn request(
|
||||
comptime path: []const u8,
|
||||
args: anytype,
|
||||
) !jetzig.testing.TestResponse {
|
||||
const options = buildOptions(self, args);
|
||||
|
||||
const allocator = self.arena.allocator();
|
||||
|
||||
const options = try buildOptions(allocator, self, args);
|
||||
const routes = try jetzig.App.createRoutes(allocator, self.routes);
|
||||
|
||||
const logger = jetzig.loggers.Logger{ .test_logger = jetzig.loggers.TestLogger{} };
|
||||
@ -113,6 +113,7 @@ pub fn request(
|
||||
.store = self.store,
|
||||
.cache = self.cache,
|
||||
.job_queue = self.job_queue,
|
||||
.global = undefined,
|
||||
};
|
||||
|
||||
try server.decodeStaticParams();
|
||||
@ -299,7 +300,7 @@ fn createStore(allocator: std.mem.Allocator) !*jetzig.kv.Store {
|
||||
return store;
|
||||
}
|
||||
|
||||
fn buildOptions(app: *const App, args: anytype) RequestOptions {
|
||||
fn buildOptions(allocator: std.mem.Allocator, app: *const App, args: anytype) !RequestOptions {
|
||||
const fields = switch (@typeInfo(@TypeOf(args))) {
|
||||
.@"struct" => |info| info.fields,
|
||||
else => @compileError("Expected struct, found `" ++ @tagName(@typeInfo(@TypeOf(args))) ++ "`"),
|
||||
@ -317,9 +318,17 @@ fn buildOptions(app: *const App, args: anytype) RequestOptions {
|
||||
}
|
||||
|
||||
return .{
|
||||
.headers = if (@hasField(@TypeOf(args), "headers")) args.headers else &.{},
|
||||
.headers = if (@hasField(@TypeOf(args), "headers")) try buildHeaders(allocator, args.headers) else &.{},
|
||||
.json = if (@hasField(@TypeOf(args), "json")) app.json(args.json) else null,
|
||||
.params = if (@hasField(@TypeOf(args), "params")) app.params(args.params) else null,
|
||||
.body = if (@hasField(@TypeOf(args), "body")) args.body else null,
|
||||
};
|
||||
}
|
||||
|
||||
fn buildHeaders(allocator: std.mem.Allocator, args: anytype) ![]const jetzig.testing.TestResponse.Header {
|
||||
var headers = std.ArrayList(jetzig.testing.TestResponse.Header).init(allocator);
|
||||
inline for (std.meta.fields(@TypeOf(args))) |field| {
|
||||
try headers.append(jetzig.testing.TestResponse.Header{ .name = field.name, .value = @field(args, field.name) });
|
||||
}
|
||||
return try headers.toOwnedSlice();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ const builtin = @import("builtin");
|
||||
const jetzig = @import("jetzig");
|
||||
pub const static = @import("static");
|
||||
|
||||
pub const std_options = .{
|
||||
pub const std_options = std.Options{
|
||||
.logFn = log,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user