mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
merge from roman
This commit is contained in:
@@ -4,12 +4,16 @@
|
||||
|
||||
Client::Client()
|
||||
{
|
||||
allRead = false;
|
||||
_received = 0;
|
||||
this->_fd = -1;
|
||||
this->_sended = 0;
|
||||
}
|
||||
|
||||
Client::Client(char *str)
|
||||
{
|
||||
allRead = false;
|
||||
_received = 0;
|
||||
this->_fd = -1;
|
||||
this->_buff = str;
|
||||
this->_sended = 0;
|
||||
@@ -18,6 +22,8 @@ Client::Client(char *str)
|
||||
|
||||
Client::Client(char *str, ServerConfig *config)
|
||||
{
|
||||
allRead = false;
|
||||
_received = 0;
|
||||
this->_fd = -1;
|
||||
this->_config = config;
|
||||
this->_buff = str;
|
||||
@@ -52,6 +58,11 @@ unsigned int Client::getCounter(void) const
|
||||
return _sended;
|
||||
}
|
||||
|
||||
unsigned int Client::getRecvCounter(void) const
|
||||
{
|
||||
return _received;
|
||||
}
|
||||
|
||||
void Client::setRawData(char *str)
|
||||
{
|
||||
this->_buff = str;
|
||||
@@ -93,11 +104,33 @@ bool Client::allSended(void)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool Client::allRecved(void)
|
||||
{
|
||||
if (_request.getContentLength() == _received)
|
||||
{
|
||||
std::cout << "contentLength, _received "
|
||||
<< _request.getContentLength()
|
||||
<< " " <<
|
||||
_received << std::endl;
|
||||
return (true);
|
||||
}
|
||||
else
|
||||
return (false);
|
||||
}
|
||||
// Функция увеличивает счетчик на количество BUFFERSIZE. Счетчик - количество байтов отправленных клиенту.
|
||||
void Client::increaseCounter(void)
|
||||
{
|
||||
_sended += BUFFSIZE;
|
||||
}
|
||||
|
||||
void Client::increaseRecvCounter(unsigned int n)
|
||||
{
|
||||
if (_received == 0)
|
||||
_received -= _request.getHeaderSize();
|
||||
_received += n;
|
||||
}
|
||||
|
||||
//Генерирует response. Далее респонс можно получить через функцию getStrToSend()
|
||||
int Client::sendResponse(int fd)
|
||||
{
|
||||
@@ -150,7 +183,8 @@ void Client::printClientInfo(void)
|
||||
std::cout << PINK << it->first << BLUE << it->second << ZERO_C << std::endl;
|
||||
}
|
||||
std::cout << TURGUOISE << "Client BODY" << ZERO_C << std::endl;
|
||||
std::cout << BLUE << _request.getBody() << ZERO_C << std::endl;
|
||||
std::cout << GREEN << _request.getBody().size() << ZERO_C << std::endl;
|
||||
/* std::cout << BLUE << _request.getBody() << ZERO_C << std::endl; */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ private:
|
||||
int _ret;
|
||||
int _fd;
|
||||
unsigned int _sended;
|
||||
unsigned int _received;
|
||||
char *_buff;
|
||||
|
||||
|
||||
@@ -25,6 +26,9 @@ private:
|
||||
std::string _headerToSend;
|
||||
std::string _toSend;
|
||||
std::map<std::string, std::string> _errorCode;
|
||||
|
||||
public:
|
||||
bool allRead;
|
||||
|
||||
public:
|
||||
Request getRequest(void);
|
||||
@@ -34,6 +38,8 @@ public:
|
||||
void setRawData(char *);
|
||||
void setFd(int);
|
||||
int getFd(void);
|
||||
unsigned int getRecvCounter(void) const;
|
||||
|
||||
|
||||
public:
|
||||
int parseRequest(void);
|
||||
@@ -42,11 +48,13 @@ public:
|
||||
|
||||
bool readyToSend(void);
|
||||
bool allSended(void);
|
||||
bool allRecved(void);
|
||||
bool isChunked(void);
|
||||
int sendResponse(int fd);
|
||||
int sendData(int , std::string data);
|
||||
void clear(void);
|
||||
void increaseCounter(void);
|
||||
void increaseRecvCounter(unsigned int n);
|
||||
std::string generateRespons(void);
|
||||
|
||||
Client();
|
||||
|
||||
@@ -10,7 +10,6 @@ Request::Request()
|
||||
_chunked = false;
|
||||
_head_ok = false;
|
||||
_body_ok = false;
|
||||
|
||||
}
|
||||
|
||||
Request::Request(char *str)
|
||||
@@ -74,6 +73,16 @@ bool Request::getChunked(void)
|
||||
{
|
||||
return (_chunked);
|
||||
}
|
||||
|
||||
unsigned int Request::getContentLength(void) const
|
||||
{
|
||||
return (_contentLength);
|
||||
}
|
||||
unsigned int Request::getHeaderSize(void) const
|
||||
{
|
||||
return (_headerSize);
|
||||
}
|
||||
|
||||
void Request::setData(char *str)
|
||||
{
|
||||
this->_data = str;
|
||||
@@ -145,6 +154,7 @@ void Request::splitData(char *data)
|
||||
return;
|
||||
}
|
||||
_head = str.substr(0, pos) + "\n";
|
||||
_headerSize = _head.size() + 3;
|
||||
str.erase(0, pos + 4);
|
||||
_head_ok = true;
|
||||
parseHeader();
|
||||
|
||||
@@ -13,6 +13,7 @@ private:
|
||||
int _ret;
|
||||
int _row;
|
||||
unsigned int _contentLength;
|
||||
unsigned int _headerSize;
|
||||
|
||||
std::string _URI;
|
||||
std::string _head;
|
||||
@@ -40,6 +41,8 @@ public:
|
||||
std::string getLocation(void);
|
||||
ServerConfig *getConfig(void);
|
||||
int getCode(void);
|
||||
unsigned int getContentLength(void) const;
|
||||
unsigned int getHeaderSize(void) const;
|
||||
std::map<std::string, std::string> getClientFields(void);
|
||||
bool getChunked(void);
|
||||
|
||||
@@ -73,4 +76,4 @@ public:
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user