Browse Source

fix waitHeader()

master
nicolas-arnaud 2 years ago
parent
commit
d012857039
  1. 2
      srcs/load/Route.cpp
  2. 19
      srcs/load/Socket.cpp

2
srcs/load/Route.cpp

@ -32,7 +32,7 @@ string Route::getRoot(void) { return _root; }
string Route::getReturn(void) { return _ret; } string Route::getReturn(void) { return _ret; }
std::vector<string> Route::getIndexsLst(void) { return _indexs; } std::vector<string> Route::getIndexsLst(void) { return _indexs; }
std::vector<string> Route::getHeadersLst(void) { return _headers; } std::vector<string> Route::getHeadersLst(void) { return _headers; }
string Route::getIndex(string uri, string path) { string Route::getIndex(string uri, string path) {
std::stringstream content; std::stringstream content;
std::stringstream ret; std::stringstream ret;

19
srcs/load/Socket.cpp

@ -100,6 +100,10 @@ void Socket::refresh(Env *env) {
} }
bool Socket::waitHeader() { bool Socket::waitHeader() {
if (_header != "")
return true;
string header;
string content;
if (_tmp.length() < 1) if (_tmp.length() < 1)
return false; return false;
std::vector<string> lines = split(_tmp, '\n'); std::vector<string> lines = split(_tmp, '\n');
@ -108,20 +112,25 @@ bool Socket::waitHeader() {
it++) { it++) {
if (*it == "\r") if (*it == "\r")
is_valid = true; is_valid = true;
else if (!is_valid)
header += *it + "\n";
else
content += *it + "\n";
} }
if (!is_valid) if (!is_valid)
return false; return false;
_header = _tmp; if (content.length() > 0)
_tmp = ""; content.at(content.length() - 1) = '\0';
_header = header;
_tmp = content;
return true; return true;
} }
int Socket::answer(Env *env, string request) { int Socket::answer(Env *env, string request) {
_tmp += request; _tmp += request;
cout << "|===|request|===>" << _tmp << "|===||\n"; cout << "|===|request|===>" << _tmp << "|===||\n";
if (_header == "") { if (!waitHeader())
waitHeader(); return EXIT_FAILURE;
}
std::vector<string> lines = split(_header, '\n'); std::vector<string> lines = split(_header, '\n');
std::vector<string> head = split(lines.at(0), ' '); std::vector<string> head = split(lines.at(0), ' ');
string uri = head.at(1); string uri = head.at(1);

Loading…
Cancel
Save