/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bcausseq +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/09/27 22:50:05 by bcausseq #+# #+# */ /* Updated: 2026/09/27 23:00:27 by bcausseq ### ########.fr */ /* */ /* ************************************************************************** */ #include "Header.hpp" #include "server/Client.hpp" #include "utils.hpp" #include #include void method_get(Header& h, Client& c) { std::string to_open = get_abs_path(c, h.get_path(), h.get_method()); if (to_open.empty()) { send_error_status(h, c, 405); return ; } errno = 0; std::string line; std::ifstream ifs; ifs.open(to_open.c_str()); if (!ifs.is_open()) { if (errno == ENOENT) send_error_status(h, c, 404); else if (errno == EACCES) send_error_status(h, c, 403); return ; } c.set_append_out_buffer(h.get_version() + " 200 OK\r\n\r\n"); while (std::getline(ifs, line)) c.set_append_out_buffer(line); }