mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
add: url decode, and change client_body_size var to ssize_t
This commit is contained in:
@@ -153,7 +153,7 @@ void CgiHandle::initEnvVariables()
|
||||
_variable["AUTH TYPE"] = it->second;
|
||||
else
|
||||
_variable["AUTH TYPE"] = "";
|
||||
_variable["CONTENT_LENGTH"] = toString(_request.getContentLength());
|
||||
_variable["CONTENT_LENGTH"] = toString(_request.getBody().size());
|
||||
it = _request.getClientFields().find("content-type");
|
||||
_variable["CONTENT_TYPE"] = "";
|
||||
_variable["GATEWAY_INTERFACE"] = std::string("CGI/1.1");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
@@ -33,7 +33,7 @@ int &ServerConfig::getPort(void)
|
||||
return (_port);
|
||||
}
|
||||
|
||||
int &ServerConfig::getClientBodySize(void)
|
||||
ssize_t &ServerConfig::getClientBodySize(void)
|
||||
{
|
||||
return (_clientBodySize);
|
||||
}
|
||||
@@ -206,7 +206,7 @@ int ServerConfig::putLocation(toml_node *node)
|
||||
else if (it1->first == "body_size_limit")
|
||||
{
|
||||
DBOUT << "BodySize in locaton" << ENDL;
|
||||
if (node->get_type() != toml_node::NUM)
|
||||
if (it1->second->get_type() != toml_node::NUM)
|
||||
continue;
|
||||
tmp->clientBodySize = it1->second->getNum();
|
||||
}
|
||||
@@ -241,7 +241,7 @@ int ServerConfig::putLocation(toml_node *node)
|
||||
tmp->redirect.insert(std::make_pair(atoi(str.c_str()), *(*it2)->getString()));
|
||||
}
|
||||
else
|
||||
std::cout << RED << it1->first << ZERO_C << std::endl;
|
||||
std::cerr << RED << "Warning: unknown parameter: "<< it1->first << ZERO_C << std::endl;
|
||||
}
|
||||
_locations.push_back(tmp);
|
||||
it++;
|
||||
|
||||
@@ -15,7 +15,7 @@ struct location
|
||||
std::vector<std::string> methods;
|
||||
std::map<int, std::string> redirect;
|
||||
std::string cgi_pass;
|
||||
unsigned int clientBodySize;
|
||||
ssize_t clientBodySize;
|
||||
};
|
||||
|
||||
struct serverListen
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
std::string _serverName;
|
||||
std::string _host;
|
||||
int _port;
|
||||
int _clientBodySize;
|
||||
ssize_t _clientBodySize;
|
||||
|
||||
std::map<int, std::string> _errorPages;
|
||||
std::vector<location *> _locations;
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
std::string &getServerName(void);
|
||||
std::string &getHost(void);
|
||||
int &getPort(void);
|
||||
int &getClientBodySize(void);
|
||||
ssize_t &getClientBodySize(void);
|
||||
std::vector<location *> &getLocations(void);
|
||||
std::map<int, std::string> &getErrorPages(void);
|
||||
TOMLMap *getRoot(void);
|
||||
|
||||
Reference in New Issue
Block a user