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::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 = "";
|
||||||
|
@ -29,16 +25,14 @@ std::string getRequestedFileName(char inBuf[DEFAULT_BUFLEN]) {
|
||||||
result += inBuf[i];
|
result += inBuf[i];
|
||||||
}
|
}
|
||||||
//std::cout << result;
|
//std::cout << result;
|
||||||
if (strstr(inBuf, "GET / HTTP/1.1") != NULL) {
|
/*if (result == "GET / HTTP/1.1") {
|
||||||
result = HOMEPAGE;
|
result = HOMEPAGE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::stringstream stream(result);
|
// GET / favicon.ico HTTP / 1.1
|
||||||
stream >> result;
|
result.replace(result.begin(), result.end(), "GET");
|
||||||
stream >> result;
|
result.replace(result.begin(), result.end(), "HTTP/1.1");
|
||||||
result.erase(0, 1);
|
}*/
|
||||||
std::cout << result << std::endl;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,18 +110,12 @@ int main() {
|
||||||
std::cout << buf;
|
std::cout << buf;
|
||||||
}
|
}
|
||||||
std::string message;
|
std::string message;
|
||||||
std::string reqFile = getRequestedFileName(buf);
|
std::cout << getRequestedFileName(buf);
|
||||||
if (fileExists(reqFile)) {
|
if (strstr(buf, "GET / HTTP/1.1") != NULL) {
|
||||||
std::ifstream line(reqFile);
|
message = content.str();
|
||||||
std::ostringstream msg;
|
|
||||||
while (std::getline(line, l))
|
|
||||||
{
|
|
||||||
msg << l;
|
|
||||||
}
|
}
|
||||||
message = msg.str();
|
else {
|
||||||
}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