diff --git a/includes/requests/HttpResponse.hpp b/includes/requests/HttpResponse.hpp index db5a7d7..1c4283b 100644 --- a/includes/requests/HttpResponse.hpp +++ b/includes/requests/HttpResponse.hpp @@ -6,7 +6,7 @@ /* By: mmoussou +typedef unsigned int uint; + namespace webserv { namespace http { @@ -26,17 +28,17 @@ public: Response(void); std::string getProtocol(void) const; - size_t getStatusCode(void) const; + uint getStatusCode(void) const; std::string getStatusText(void) const; void setProtocol(std::string const protocol); - void setStatusCode(size_t const status_code); + void setStatusCode(uint const status_code); std::string str(void) const; private: std::string _protocol; - size_t _status_code; + uint _status_code; std::string _status_text; }; diff --git a/src/requests_handling/HttpRequests.cpp b/src/requests_handling/HttpRequests.cpp index c17f982..7b205fe 100644 --- a/src/requests_handling/HttpRequests.cpp +++ b/src/requests_handling/HttpRequests.cpp @@ -6,7 +6,7 @@ /* By: mmoussou #include +#include #include #include @@ -107,7 +108,7 @@ void http::Get::parse(std::string const &data) body_stream << line << "\n"; this->_body = body_stream.str(); - ///* + /* std::cout << "-- start-line --" << std::endl; std::cout << "method: " << this->_method << std::endl; std::cout << "target: " << this->_target << std::endl; @@ -118,13 +119,17 @@ void http::Get::parse(std::string const &data) std::cout << it->first << ": " << it->second << std::endl; std::cout << std::endl; std::cout << "-- body --" << std::endl << this->_body << std::endl; - //*/ + */ } -char isDirectory(const std::string& path) { +char isDirectory(const std::string& path) +{ struct stat file_stat; + if (stat(path.c_str(), &file_stat) != 0) - throw; + { + throw std::runtime_error("can't open file (non-existant ?)"); + } return S_ISDIR(file_stat.st_mode); } @@ -202,7 +207,7 @@ http::Response http::Get::execute(void) response.setProtocol(this->_protocol); response.setStatusCode(404); response.addHeader("Content-Type", "text/html"); - response.setBody("nuh uh, get 404'd >:D"); + response.setBody(http::Errors::getResponseBody(response.getStatusCode())); } return (response); @@ -247,7 +252,7 @@ void http::Delete::parse(std::string const &data) body_stream << line << "\n"; this->_body = body_stream.str(); - ///* + /* std::cout << "-- start-line --" << std::endl; std::cout << "method: " << this->_method << std::endl; std::cout << "target: " << this->_target << std::endl; @@ -258,7 +263,7 @@ void http::Delete::parse(std::string const &data) std::cout << it->first << ": " << it->second << std::endl; std::cout << std::endl; std::cout << "-- body --" << std::endl << this->_body << std::endl; - //*/ + */ } http::Response http::Delete::execute(void) @@ -268,7 +273,7 @@ http::Response http::Delete::execute(void) try { if (std::remove(this->_target.c_str())) - throw; + throw std::runtime_error("can't remove file, FF"); response.setProtocol(this->_protocol); response.setStatusCode(204); // this cool dude on the internet said i should not do that so i'll change it https://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/ time_t now = std::time(NULL); @@ -281,7 +286,7 @@ http::Response http::Delete::execute(void) response.setProtocol(this->_protocol); response.setStatusCode(404); response.addHeader("Content-Type", "text/html"); - response.setBody("nuh uh, get 404'd >:D"); + response.setBody(http::Errors::getResponseBody(response.getStatusCode())); } return (response); diff --git a/src/requests_handling/HttpResponse.cpp b/src/requests_handling/HttpResponse.cpp index 0626827..7810f18 100644 --- a/src/requests_handling/HttpResponse.cpp +++ b/src/requests_handling/HttpResponse.cpp @@ -6,7 +6,7 @@ /* By: mmoussou _protocol); } -size_t http::Response::getStatusCode(void) const +uint http::Response::getStatusCode(void) const { return (this->_status_code); } @@ -64,7 +64,7 @@ void http::Response::setProtocol(std::string const protocol) this->_protocol = protocol; } -void http::Response::setStatusCode(size_t const status_code) +void http::Response::setStatusCode(uint const status_code) { this->_status_code = status_code; this->_status_text = Errors::message[status_code];