mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
delete Headerhandl class
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
# define HEADER_HPP
|
||||
|
||||
#include "webserv.hpp"
|
||||
#include "HeaderHandl.hpp"
|
||||
#include "Autoindex.hpp"
|
||||
#include "ServerConfig.hpp"
|
||||
#include "Request.hpp"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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---------------------------------------
|
||||
|
||||
|
||||
@@ -15,23 +15,29 @@ private:
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> _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();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user