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