delete Headerhandl class

This commit is contained in:
Talyx
2022-01-27 14:29:12 +03:00
parent 2f0b3bddbe
commit feb298a944
5 changed files with 43 additions and 73 deletions

View File

@@ -2,7 +2,6 @@
# define HEADER_HPP # define HEADER_HPP
#include "webserv.hpp" #include "webserv.hpp"
#include "HeaderHandl.hpp"
#include "Autoindex.hpp" #include "Autoindex.hpp"
#include "ServerConfig.hpp" #include "ServerConfig.hpp"
#include "Request.hpp" #include "Request.hpp"

View File

@@ -1,17 +0,0 @@
#include "HeaderHandl.hpp"
HeaderHandl::HeaderHandl()
{
}
HeaderHandl::~HeaderHandl()
{
}
void HeaderHandl::copyData(std::map<std::string, std::string> map)
{
_host = map.find("host")->second;
}

View File

@@ -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<std::string> _methods;
std::map<int, std::string> _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<std::string, std::string>);
~HeaderHandl();
};
#endif

View File

@@ -48,20 +48,49 @@ void Respons::OpenResponsFile(const char *path)
} }
void Respons::generate() 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::stringstream ss;
std::string tmp; std::string tmp;
//header
ss << _request.getVersion() << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode()) << "\r\nContent-Type: text/html\r\n\r\n"; ss << _request.getVersion() << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode()) << "\r\nContent-Type: text/html\r\n\r\n";
_header = ss.str(); _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) if (!_request.badCode(_request.getCode()) && _request.isDir(_request.getFullUri()) == 0)
_body = Autoindex::getPage(_request.getURI(), _request.getFullUri(), _request.getHost()); _body = Autoindex::getPage(_request.getURI(), _request.getFullUri(), _request.getHost());
else if (!_request.badCode(_request.getCode())) else if (!_request.badCode(_request.getCode()))
OpenResponsFile(_request.getFullUri().c_str()); OpenResponsFile(_request.getFullUri().c_str());
else else
getErrorPage(_request.getCode()); _body = getErrorPage(_request.getCode());
} std::cout << GREEN << "GET method called\n" << ZERO_C;
}
//-------------------------------------------------GET/SET--------------------------------------- //-------------------------------------------------GET/SET---------------------------------------

View File

@@ -16,22 +16,28 @@ private:
private: private:
std::map<std::string, std::string> _errorCode; std::map<std::string, std::string> _errorCode;
private:
void methodGet(void);
// void methodPost(void);
// void methodDelete(void);
void invalidHeader(void);
public: public:
std::string getHeader(void); std::string getHeader(void);
std::string getBody(void); std::string getBody(void);
std::string getReasonPhrase(std::string); std::string getReasonPhrase(std::string);
std::string getReasonPhrase(int); std::string getReasonPhrase(int);
std::string getErrorPage(int code); std::string getErrorPage(int code);
void setData(Request, ServerConfig *); void setData(Request, ServerConfig *);
public: public:
void OpenResponsFile(const char *path); void OpenResponsFile(const char *path);
void initErrorCode(void); void initErrorCode(void);
void generate(); void generate();
Respons(); Respons();
~Respons(); ~Respons();
}; };