mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
update class client, request
This commit is contained in:
@@ -5,12 +5,14 @@
|
||||
Client::Client()
|
||||
{
|
||||
this->_fd = -1;
|
||||
this->_sended = 0;
|
||||
}
|
||||
|
||||
Client::Client(char *str)
|
||||
{
|
||||
this->_fd = -1;
|
||||
this->_buff = str;
|
||||
this->_sended = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +21,7 @@ Client::Client(char *str, ServerConfig *config)
|
||||
this->_fd = -1;
|
||||
this->_config = config;
|
||||
this->_buff = str;
|
||||
this->_sended = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +34,12 @@ Request Client::getRequest(void)
|
||||
|
||||
Response Client::getResponse(void)
|
||||
{
|
||||
return (_Response);
|
||||
return (_response);
|
||||
}
|
||||
|
||||
std::string Client::getStrToSend(void)
|
||||
{
|
||||
return (_toSend);
|
||||
}
|
||||
|
||||
int Client::getFd(void)
|
||||
@@ -49,6 +57,7 @@ void Client::setFd(int fd)
|
||||
this->_fd = fd;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------Parsing---------------------------------------
|
||||
|
||||
int Client::parseRequest(void)
|
||||
@@ -68,23 +77,55 @@ int Client::sendData(int fd, std::string data)
|
||||
{
|
||||
return (send(fd, data.c_str(), data.length(), 0));
|
||||
}
|
||||
|
||||
//Возвращает истина, если запрос chunked.
|
||||
bool Client::isChunked(void)
|
||||
{
|
||||
return (_request.getChunked());
|
||||
}
|
||||
// Возвращает истина, если отправлены все данные клиента.
|
||||
bool Client::allSended(void)
|
||||
{
|
||||
if (_toSend.size() <= _sended)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
// Функция увеличивает счетчик на количество BUFFERSIZE. Счетчик - количество байтов отправленных клиенту.
|
||||
void Client::increaseCounter(void)
|
||||
{
|
||||
_sended += BUFFSIZE;
|
||||
}
|
||||
//Генерирует response. Далее респонс можно получить через функцию getStrToSend()
|
||||
int Client::sendResponse(int fd)
|
||||
{
|
||||
_Response.setData(_request, _config);
|
||||
_Response.generate();
|
||||
_ClientToSend = _Response.getClient();
|
||||
_bodyToSend = _Response.getBody();
|
||||
_ret = sendData(fd, _ClientToSend);
|
||||
_ret = sendData(fd, _bodyToSend);
|
||||
_response.setData(_request, _config);
|
||||
_response.generate();
|
||||
_headerToSend = _response.getClient();
|
||||
_bodyToSend = _response.getBody();
|
||||
_ret = sendData(fd, _headerToSend + _bodyToSend);
|
||||
|
||||
return (_ret);
|
||||
}
|
||||
|
||||
std::string Client::generateRespons(void)
|
||||
{
|
||||
_response.setData(_request, _config);
|
||||
_response.generate();
|
||||
_headerToSend = _response.getClient();
|
||||
_bodyToSend = _response.getBody();
|
||||
_toSend = _headerToSend + _bodyToSend;
|
||||
|
||||
return (_toSend);
|
||||
}
|
||||
|
||||
//-------------------------------------------------Error---------------------------------------
|
||||
|
||||
//-------------------------------------------------Other---------------------------------------
|
||||
|
||||
bool Client::readyToSend(void)
|
||||
{
|
||||
return(_request.ok());
|
||||
}
|
||||
|
||||
void Client::printClientInfo(void)
|
||||
{
|
||||
std::map<std::string, std::string> map;
|
||||
@@ -97,14 +138,15 @@ void Client::printClientInfo(void)
|
||||
std::cout << PINK << "host = " << _request.getHost() << ZERO_C << std::endl;
|
||||
std::cout << PINK << "request query = " << _request.getQuery() << ZERO_C << std::endl;
|
||||
std::cout << PINK << "request http versioin = " << _request.getVersion() << ZERO_C << std::endl;
|
||||
std::cout << YELLOW << "request Client:\n" << _buff << ZERO_C << std::endl;
|
||||
// std::cout << YELLOW << "request Client:\n" << _buff << ZERO_C << std::endl;
|
||||
|
||||
std::cout << TURGUOISE << "Client MAP" << ZERO_C << std::endl;
|
||||
for ( it = map.begin(); it != map.end() ; it++)
|
||||
{
|
||||
std::cout << PINK << it->first << BLUE << it->second << ZERO_C << std::endl;
|
||||
// std::cout << "1\n";
|
||||
}
|
||||
std::cout << TURGUOISE << "Client BODY" << ZERO_C << std::endl;
|
||||
std::cout << BLUE << _request.getBody() << ZERO_C << std::endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +158,9 @@ void Client::clear(void)
|
||||
_request.clear();
|
||||
_buff = NULL;
|
||||
_config = NULL;
|
||||
_bodyToSend = "";
|
||||
_headerToSend = "";
|
||||
_toSend = "";
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
|
||||
Reference in New Issue
Block a user