Compare commits
2 commits
0488bfb687
...
545568ac16
Author | SHA1 | Date | |
---|---|---|---|
545568ac16 | |||
ed21e01b89 |
2 changed files with 24 additions and 12 deletions
BIN
Web_Test/favicon.ico
Normal file
BIN
Web_Test/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 318 B |
|
@ -14,9 +14,13 @@ int res;
|
||||||
std::ostringstream content;
|
std::ostringstream content;
|
||||||
std::string l;
|
std::string l;
|
||||||
char buf[DEFAULT_BUFLEN];
|
char buf[DEFAULT_BUFLEN];
|
||||||
|
bool fileExists(std::string path) {
|
||||||
|
std::fstream file(path);
|
||||||
|
return file.good();
|
||||||
|
}
|
||||||
std::string getRequestedFileName(char inBuf[DEFAULT_BUFLEN]) {
|
std::string getRequestedFileName(char inBuf[DEFAULT_BUFLEN]) {
|
||||||
if (strstr(inBuf,"GET") == NULL) {
|
if (strstr(inBuf,"GET") == NULL) {
|
||||||
|
//Invalid request
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
@ -25,14 +29,16 @@ std::string getRequestedFileName(char inBuf[DEFAULT_BUFLEN]) {
|
||||||
result += inBuf[i];
|
result += inBuf[i];
|
||||||
}
|
}
|
||||||
//std::cout << result;
|
//std::cout << result;
|
||||||
/*if (result == "GET / HTTP/1.1") {
|
if (strstr(inBuf, "GET / HTTP/1.1") != NULL) {
|
||||||
result = HOMEPAGE;
|
result = HOMEPAGE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// GET / favicon.ico HTTP / 1.1
|
std::stringstream stream(result);
|
||||||
result.replace(result.begin(), result.end(), "GET");
|
stream >> result;
|
||||||
result.replace(result.begin(), result.end(), "HTTP/1.1");
|
stream >> result;
|
||||||
}*/
|
result.erase(0, 1);
|
||||||
|
std::cout << result << std::endl;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +116,18 @@ int main() {
|
||||||
std::cout << buf;
|
std::cout << buf;
|
||||||
}
|
}
|
||||||
std::string message;
|
std::string message;
|
||||||
std::cout << getRequestedFileName(buf);
|
std::string reqFile = getRequestedFileName(buf);
|
||||||
if (strstr(buf, "GET / HTTP/1.1") != NULL) {
|
if (fileExists(reqFile)) {
|
||||||
message = content.str();
|
std::ifstream line(reqFile);
|
||||||
}
|
std::ostringstream msg;
|
||||||
else {
|
while (std::getline(line, l))
|
||||||
|
{
|
||||||
|
msg << l;
|
||||||
|
}
|
||||||
|
message = msg.str();
|
||||||
|
}else{
|
||||||
|
//Error 404
|
||||||
|
std::cout << "Error 404!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
res = send(client, message.c_str(), message.size(), 0);
|
res = send(client, message.c_str(), message.size(), 0);
|
||||||
|
|
Loading…
Reference in a new issue