-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetNextRequest issue #39
Comments
For a request to be incomplete, it is not only about the CRLF sequences not showing up, in fact, the sequence might be in the request, but the content not be complete. The sequence appears at the end of the headers section, and in the case of POST requests, at the end of the body section as well. On top of that, in POST request, the sequence can be at the end of the request, but if the Content Length is not the same as the received body length, then the request is also considered incomplete. I think that part is missing, therefore, my suggestion: static std::string buff;
std::string ret;
// adding req_str to buff
if (req_str != "") { buff += req_str; }
size_t end_headers = buff.find("\r\n\r\n");
// Request is incomplete
if (end_headers == std::string::npos) { return (""); }
// getting request until the end of headers
ret = buff.substr(0, end_headers + 4);
// getting Content-Length
size_t pos;
if ((pos = ret.find("Content-Length: ")) != std::string::npos) {
// getting Content-Length
std::string l;
std::istringstream iss(buff.substr(pos + 16));
iss >> l;
// converting to int
int len;
std::stringstream ss(l);
ss >> len;
// getting body of request
std::string body = buff.substr(end_headers + 4);
// adding body to ret
if (len == body.size()) { ret += buff.substr(end_headers + 4, len); }
else { return (""); }
}
buff = buff.substr(ret.size());
return (ret);
} Also, I dont agree that an incomplete request should return an empty string. I think an incomplete request should be in the loop for getNextRequest() so it stops being incomplete and becomes complete at some point. In the case above I used the return empty string so it would be consistent with the proposal, but what if we did |
I think we all understood this problem. I have this proposal:
what this means:
This means ServerSocket and SocketConnection will need a getNextRequest function. And that HTTPRequest will need to be refactored.
This is my proposal for
getNextRequest
function inSocketConnection
This function returns 0 if a request is incomplete. If somehow the req_str has more than one request, by calling it on a loop like we do in the http_handle function we will be able to receive all complete requests.
The text was updated successfully, but these errors were encountered: