Fix compile errors on parse errors
This commit is contained in:
parent
61c989acde
commit
f86873395b
1 changed files with 4 additions and 6 deletions
|
@ -38,7 +38,7 @@ const HttpServer = struct {
|
||||||
errdefer conn.close();
|
errdefer conn.close();
|
||||||
|
|
||||||
const req = http.Request.parse(alloc, conn.stream.reader()) catch |err| {
|
const req = http.Request.parse(alloc, conn.stream.reader()) catch |err| {
|
||||||
_ = handleError(conn.stream.writer(), err);
|
handleError(conn.stream.writer(), err) catch unreachable;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,17 +51,15 @@ const HttpServer = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: We should get more specific about what type of errors can happen
|
||||||
fn handleError(writer: anytype, err: anyerror) !void {
|
fn handleError(writer: anytype, err: anyerror) !void {
|
||||||
const status: http.Status = switch (err) {
|
const status: http.Status = switch (err) {
|
||||||
error.BadRequest => .bad_request,
|
error.BadRequest => .bad_request,
|
||||||
error.MethodNotImplemented => .method_not_implemented,
|
|
||||||
error.UnknownProtocol => .unknown_protocol,
|
|
||||||
error.UnsupportedMediaType => .unsupported_media_type,
|
error.UnsupportedMediaType => .unsupported_media_type,
|
||||||
error.RequestEntityTooLarge => .request_entity_too_large,
|
|
||||||
error.HttpVersionNotSupported => .http_version_not_supported,
|
error.HttpVersionNotSupported => .http_version_not_supported,
|
||||||
|
|
||||||
else => err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
|
||||||
try writer.print("HTTP/1.1 {} {}\r\n\r\n", .{ @enumToInt(status), status.phrase() });
|
try writer.print("HTTP/1.1 {} {s}\r\n\r\n", .{ @enumToInt(status), status.phrase() });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue