From feb298a9443089c739f6c76403c806841383d533 Mon Sep 17 00:00:00 2001 From: Talyx Date: Thu, 27 Jan 2022 14:29:12 +0300 Subject: [PATCH] delete Headerhandl class --- src/Header/Header.hpp | 1 - src/Header/HeaderHandl.cpp | 17 -------------- src/Header/HeaderHandl.hpp | 47 -------------------------------------- src/Header/Respons.cpp | 35 +++++++++++++++++++++++++--- src/Header/Respons.hpp | 16 +++++++++---- 5 files changed, 43 insertions(+), 73 deletions(-) delete mode 100644 src/Header/HeaderHandl.cpp delete mode 100644 src/Header/HeaderHandl.hpp diff --git a/src/Header/Header.hpp b/src/Header/Header.hpp index d4093e4..044e913 100644 --- a/src/Header/Header.hpp +++ b/src/Header/Header.hpp @@ -2,7 +2,6 @@ # define HEADER_HPP #include "webserv.hpp" -#include "HeaderHandl.hpp" #include "Autoindex.hpp" #include "ServerConfig.hpp" #include "Request.hpp" diff --git a/src/Header/HeaderHandl.cpp b/src/Header/HeaderHandl.cpp deleted file mode 100644 index 71f65fc..0000000 --- a/src/Header/HeaderHandl.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "HeaderHandl.hpp" - - -HeaderHandl::HeaderHandl() -{ - -} - -HeaderHandl::~HeaderHandl() -{ - -} - -void HeaderHandl::copyData(std::map map) -{ - _host = map.find("host")->second; -} diff --git a/src/Header/HeaderHandl.hpp b/src/Header/HeaderHandl.hpp deleted file mode 100644 index 4984d95..0000000 --- a/src/Header/HeaderHandl.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef HEADERHANDL_HPP -#define HEADERHANDL_HPP - -#include "webserv.hpp" - -class HeaderHandl -{ - -public: - std::string _location; - std::string _root; - std::string _directoryFile; - std::string _uploadDir; - bool _autoindex; - bool _uploadAccept; - std::vector _methods; - std::map _redirect; -public: - std::string _type; - std::string _method; - std::string _URI; - std::string _fullURI; - std::string _version; - std::string _query; -public: - // std::string _allow; - // std::string _contentLenght; - std::string _contentType; - std::string _host; - // std::string _contentLanguage; - std::string _contentLocation; - // std::string _date; - // std::string _lastModified; - // std::string _transferEncoding; - // std::string _server; - // std::string _location; -public: - HeaderHandl(); - - void copyData(std::map); - - ~HeaderHandl(); -}; - - - -#endif \ No newline at end of file diff --git a/src/Header/Respons.cpp b/src/Header/Respons.cpp index 24312de..05f06dd 100644 --- a/src/Header/Respons.cpp +++ b/src/Header/Respons.cpp @@ -48,20 +48,49 @@ void Respons::OpenResponsFile(const char *path) } void Respons::generate() +{ + if (_request.badCode(_request.getCode())) + invalidHeader(); + else if (_request.getMethod() == "GET") + methodGet(); + // else if (_request.getMethod() == "POST") + // methodPost(); + // else + // methodDelete(); +} + +//-------------------------------------------------GET/SET--------------------------------------- + +void Respons::invalidHeader(void) { std::stringstream ss; std::string tmp; - + //header ss << _request.getVersion() << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode()) << "\r\nContent-Type: text/html\r\n\r\n"; _header = ss.str(); + + //body + _body = getErrorPage(_request.getCode()); + std::cout << RED << "Invalid Header method called\n" << ZERO_C; +} + +void Respons::methodGet(void) +{ + std::stringstream ss; + std::string tmp; + //header + ss << _request.getVersion() << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode()) << "\r\nContent-Type: text/html\r\n\r\n"; + _header = ss.str(); + //body if (!_request.badCode(_request.getCode()) && _request.isDir(_request.getFullUri()) == 0) _body = Autoindex::getPage(_request.getURI(), _request.getFullUri(), _request.getHost()); else if (!_request.badCode(_request.getCode())) OpenResponsFile(_request.getFullUri().c_str()); else - getErrorPage(_request.getCode()); -} + _body = getErrorPage(_request.getCode()); + std::cout << GREEN << "GET method called\n" << ZERO_C; +} //-------------------------------------------------GET/SET--------------------------------------- diff --git a/src/Header/Respons.hpp b/src/Header/Respons.hpp index 87422ad..9bcdeb4 100644 --- a/src/Header/Respons.hpp +++ b/src/Header/Respons.hpp @@ -15,23 +15,29 @@ private: private: std::map _errorCode; - + +private: + void methodGet(void); + // void methodPost(void); + // void methodDelete(void); + void invalidHeader(void); + public: - std::string getHeader(void); - std::string getBody(void); + std::string getHeader(void); + std::string getBody(void); std::string getReasonPhrase(std::string); std::string getReasonPhrase(int); std::string getErrorPage(int code); - void setData(Request, ServerConfig *); + void setData(Request, ServerConfig *); public: - void OpenResponsFile(const char *path); void initErrorCode(void); void generate(); Respons(); ~Respons(); + };