support for new data types
@@ -31,17 +31,11 @@ void Response::setData(Request request, ServerConfig *config)
|
|||||||
void Response::OpenResponseFile(const char *path)
|
void Response::OpenResponseFile(const char *path)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
char buf[BUFFSIZE + 1] = {0};
|
std::ifstream file(path, std::ifstream::in);
|
||||||
std::ifstream file(path);
|
|
||||||
|
|
||||||
if (file.is_open())
|
if (file.is_open())
|
||||||
{
|
{
|
||||||
while (!file.eof())
|
ss << file.rdbuf();
|
||||||
{
|
|
||||||
file.read(buf, BUFFSIZE);
|
|
||||||
ss << buf;
|
|
||||||
memset(buf, 0, BUFFSIZE + 1);
|
|
||||||
}
|
|
||||||
_body = ss.str();
|
_body = ss.str();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -61,7 +55,44 @@ void Response::generate()
|
|||||||
// methodDelete();
|
// methodDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------GET/SET---------------------------------------
|
//-------------------------------------------------HEADER/BODY---------------------------------------
|
||||||
|
|
||||||
|
std::string Response::getTime(void)
|
||||||
|
{
|
||||||
|
char buff[1337] = {0};
|
||||||
|
struct timeval currTime;
|
||||||
|
struct tm *t;
|
||||||
|
|
||||||
|
gettimeofday(&currTime, NULL);
|
||||||
|
t = gmtime(&currTime.tv_sec);
|
||||||
|
strftime(buff, 1337, "%a, %d %b %Y %H:%M:%S GTM", t);
|
||||||
|
|
||||||
|
return (buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Response::getContentType(void)
|
||||||
|
{
|
||||||
|
std::string path = _request.getFullUri();
|
||||||
|
std::string type = path.substr(path.rfind(".") + 1, path.size() - path.rfind("."));
|
||||||
|
|
||||||
|
if (_request.isDir(path) == 0)
|
||||||
|
return ("text/html");
|
||||||
|
else if (type == "html")
|
||||||
|
return ("text/html");
|
||||||
|
else if (type == "css")
|
||||||
|
return ("text/css");
|
||||||
|
else if (type == "js")
|
||||||
|
return ("text/javascript");
|
||||||
|
else if (type == "jpeg" || type == "jpg")
|
||||||
|
return ("image/jpeg");
|
||||||
|
else if (type == "png")
|
||||||
|
return ("image/png");
|
||||||
|
else if (type == "bmp")
|
||||||
|
return ( "image/bmp");
|
||||||
|
else
|
||||||
|
return ("text/plain");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Response::invalidClient(void)
|
void Response::invalidClient(void)
|
||||||
{
|
{
|
||||||
@@ -82,6 +113,8 @@ void Response::generateBody(void)
|
|||||||
_body = Autoindex::getPage(_request.getURI(), _request.getFullUri(), _request.getHost());
|
_body = Autoindex::getPage(_request.getURI(), _request.getFullUri(), _request.getHost());
|
||||||
else if (!_request.badCode(_code) && _request.isFile(_request.getFullUri()) == 0)
|
else if (!_request.badCode(_code) && _request.isFile(_request.getFullUri()) == 0)
|
||||||
OpenResponseFile(_request.getFullUri().c_str());
|
OpenResponseFile(_request.getFullUri().c_str());
|
||||||
|
else if (_request.isFile(_request.getFullUri()) == -1)
|
||||||
|
_body = getErrorPage(404);
|
||||||
else
|
else
|
||||||
_body = getErrorPage(_code);
|
_body = getErrorPage(_code);
|
||||||
|
|
||||||
@@ -92,11 +125,14 @@ void Response::generateHeader(void)
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
|
||||||
ss << "HTTP/1.1" << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode())
|
ss << "HTTP/1.1" << " " << _request.getCode() << " " << getReasonPhrase(_request.getCode()) << "\r\n";
|
||||||
<< "\r\nContent-Type: text/html"
|
ss << "Content-Type: " << getContentType() << "\r\n";
|
||||||
<< "\r\nContent-Length: " << _body.size()
|
ss << "Content-Length: " << _body.size() << "\r\n";
|
||||||
<< "\r\nServer: poheck"
|
ss << "Server: poheck\r\n";
|
||||||
<< "\r\n\r\n";
|
if (_request.getConnection() == "keep-alive")
|
||||||
|
ss << "Keep-Alive: timeout=" << _request.getLifeTime() << "\r\n";
|
||||||
|
ss << "Date: " << getTime() << "\r\n";
|
||||||
|
ss << "\r\n";
|
||||||
_header = ss.str();
|
_header = ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ private:
|
|||||||
// void methodPost(void);
|
// void methodPost(void);
|
||||||
// void methodDelete(void);
|
// void methodDelete(void);
|
||||||
void invalidClient(void);
|
void invalidClient(void);
|
||||||
void generateHeader(void);
|
void generateHeader(void);
|
||||||
void generateBody(void);
|
void generateBody(void);
|
||||||
|
std::string getTime(void);
|
||||||
|
std::string getContentType(void);
|
||||||
public:
|
public:
|
||||||
std::string getHeader(void);
|
std::string getHeader(void);
|
||||||
std::string getBody(void);
|
std::string getBody(void);
|
||||||
|
|||||||
BIN
www/images/images.jpeg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
www/images/images1.jpeg
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
www/images/images2.jpeg
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
www/images/images3.jpeg
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
www/images/images4.jpeg
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
www/images/images5.jpeg
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
www/images/index.jpeg
Normal file
|
After Width: | Height: | Size: 5.5 KiB |