add: url decode, and change client_body_size var to ssize_t

This commit is contained in:
Talyx
2022-02-14 17:34:01 +03:00
parent cec4ae69e1
commit b1a1404863
7 changed files with 40 additions and 17 deletions

View File

@@ -89,7 +89,7 @@ bool Request::getChunked(void)
return (_chunked);
}
unsigned int Request::getContentLength(void) const
ssize_t Request::getContentLength(void) const
{
return (_contentLength);
}
@@ -97,7 +97,7 @@ unsigned int Request::getHeaderSize(void) const
{
return (_headerSize);
}
unsigned int Request::getRecved(void) const
ssize_t Request::getRecved(void) const
{
return (_received);
}
@@ -127,6 +127,25 @@ void Request::increaseRecvCounter(unsigned int n)
{
_received += n;
}
std::string urlDecode(std::string &url) {
std::string ret;
char ch;
size_t i, ii;
for (i=0; i < url.length(); i++) {
if (size_t(url[i])==37) {
sscanf(url.substr(i+1,2).c_str(), "%lx", &ii);
ch=static_cast<char>(ii);
ret+=ch;
i=i+2;
} else {
ret+=url[i];
}
}
return (ret);
}
void Request::parseURI(std::string str)
{
std::string tmp;
@@ -141,6 +160,10 @@ void Request::parseURI(std::string str)
}
else
_URI = str;
std::string sIn = _URI;
_URI = urlDecode(sIn);
_fullURI = HOME + _URI;
}

View File

@@ -14,8 +14,8 @@ private:
int _ret;
int _row;
int _lifeTime;
unsigned int _contentLength;
unsigned int _received;
ssize_t _contentLength;
ssize_t _received;
unsigned int _headerSize;
std::string _URI;
@@ -48,9 +48,9 @@ public:
ServerConfig *getConfig(void);
int getCode(void);
int getLifeTime(void);
unsigned int getContentLength(void) const;
ssize_t getContentLength(void) const;
unsigned int getHeaderSize(void) const;
unsigned int getRecved(void)const;
ssize_t getRecved(void)const;
char *getPointerBody(void)const;
std::map<std::string, std::string> getClientFields(void);

View File

@@ -103,7 +103,7 @@ std::string Response::getCgiPass(void)
return (_location->cgi_pass);
}
unsigned int Response::getMaxBodySize(void)
ssize_t Response::getMaxBodySize(void)
{
return (_maxBodySize);
}

View File

@@ -25,8 +25,8 @@ private:
private:
std::string _contentType;
unsigned int _contentLength;
unsigned int _maxBodySize;
ssize_t _contentLength;
ssize_t _maxBodySize;
std::string _server;
std::string _keepAlive;
std::string _date;
@@ -67,7 +67,7 @@ public:
static std::string getReasonPhrase(int);
std::string getErrorPage(int code);
std::string getFullURI();
unsigned int getMaxBodySize(void);
ssize_t getMaxBodySize(void);
bool isRedirect(void);
bool allowedMethod(std::string &);
void setData(Request, ServerConfig *);