diff --git a/srcs/load/Route.cpp b/srcs/load/Route.cpp index 70f62fb..a3ebf63 100644 --- a/srcs/load/Route.cpp +++ b/srcs/load/Route.cpp @@ -32,7 +32,7 @@ string Route::getRoot(void) { return _root; } string Route::getReturn(void) { return _ret; } std::vector Route::getIndexsLst(void) { return _indexs; } std::vector Route::getHeadersLst(void) { return _headers; } - + string Route::getIndex(string uri, string path) { std::stringstream content; std::stringstream ret; diff --git a/srcs/load/Socket.cpp b/srcs/load/Socket.cpp index 029bbaf..560002e 100644 --- a/srcs/load/Socket.cpp +++ b/srcs/load/Socket.cpp @@ -100,6 +100,10 @@ void Socket::refresh(Env *env) { } bool Socket::waitHeader() { + if (_header != "") + return true; + string header; + string content; if (_tmp.length() < 1) return false; std::vector lines = split(_tmp, '\n'); @@ -108,20 +112,25 @@ bool Socket::waitHeader() { it++) { if (*it == "\r") is_valid = true; + else if (!is_valid) + header += *it + "\n"; + else + content += *it + "\n"; } if (!is_valid) return false; - _header = _tmp; - _tmp = ""; + if (content.length() > 0) + content.at(content.length() - 1) = '\0'; + _header = header; + _tmp = content; return true; } int Socket::answer(Env *env, string request) { _tmp += request; cout << "|===|request|===>" << _tmp << "|===||\n"; - if (_header == "") { - waitHeader(); - } + if (!waitHeader()) + return EXIT_FAILURE; std::vector lines = split(_header, '\n'); std::vector head = split(lines.at(0), ' '); string uri = head.at(1);