Browse Source

fix waitHeader()

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

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