This commit is contained in:
Bob Farrell 2024-05-06 13:58:30 +01:00
parent d8b8ffd1d4
commit c84d2fcd71
3 changed files with 8 additions and 45 deletions

View File

@ -94,9 +94,6 @@ pub fn start(self: App, routes_module: type, options: AppOptions) !void {
std.process.exit(0);
}
// var httpz_server = try jetzig.HttpzServer.init(self.allocator);
// defer httpz_server.deinit();
var server = jetzig.http.Server.init(
self.allocator,
server_options,

View File

@ -183,24 +183,16 @@ pub fn respond(self: *Request) !void {
defer std_response_headers.deinit(self.allocator);
for (self.response.headers.headers.items) |header| {
self.httpz_response.header(header.name, header.value);
self.httpz_response.header(
try self.httpz_response.arena.dupe(u8, header.name),
try self.httpz_response.arena.dupe(u8, header.value),
);
}
const status = jetzig.http.status_codes.get(self.response.status_code);
self.httpz_response.status = try status.getCodeInt();
self.httpz_response.body = self.response.content;
try self.httpz_response.write();
// try self.httpz_response.respond(
// self.response.content,
// .{
// .keep_alive = false,
// .status = switch (self.response.status_code) {
// inline else => |tag| @field(std.http.Status, @tagName(tag)),
// },
// .extra_headers = std_response_headers.items,
// },
// );
self.httpz_response.body = try self.httpz_response.arena.dupe(u8, self.response.content);
// try self.httpz_response.write();
}
/// Render a response. This function can only be called once per request (repeat calls will

View File

@ -66,8 +66,8 @@ pub fn listen(self: *Server) !void {
.{
.port = self.options.port,
.address = self.options.bind,
.workers = .{ .count = 8 },
.thread_pool = .{ .count = 8 },
.workers = .{ .count = 20 },
.thread_pool = .{ .count = 1 },
},
self,
);
@ -131,32 +131,6 @@ fn processNextRequest(
// try self.logger.logRequest(&request);
}
// fn processNextRequest(self: *Server, allocator: std.mem.Allocator, std_http_server: *std.http.Server) !void {
// const start_time = std.time.nanoTimestamp();
//
// const std_http_request = try std_http_server.receiveHead();
// if (std_http_server.state == .receiving_head) return error.JetzigParseHeadError;
//
// var response = try jetzig.http.Response.init(allocator);
// var request = try jetzig.http.Request.init(allocator, self, start_time, std_http_request, &response);
//
// try request.process();
//
// var middleware_data = try jetzig.http.middleware.afterRequest(&request);
//
// try self.renderResponse(&request);
// try request.response.headers.append("content-type", response.content_type);
//
// try jetzig.http.middleware.beforeResponse(&middleware_data, &request);
//
// try request.respond();
//
// try jetzig.http.middleware.afterResponse(&middleware_data, &request);
// jetzig.http.middleware.deinit(&middleware_data, &request);
//
// try self.logger.logRequest(&request);
// }
//
fn renderResponse(self: *Server, request: *jetzig.http.Request) !void {
const static_resource = self.matchStaticResource(request) catch |err| {
if (isUnhandledError(err)) return err;