Merge branch 'hugo2'
+ changed the appropriate getters for client + moved the functions to parse the http message (first line, headers, and body) outside client, in parsing_http_message.cpp + resolved some of the throw problems
This commit is contained in:
@@ -17,15 +17,15 @@ void Webserv::_response(Client *client)
|
||||
|
||||
if (ret == SEND_CLOSE)
|
||||
{
|
||||
_close_client(client->fd);
|
||||
_close_client(client->get_cl_fd());
|
||||
}
|
||||
else if (ret == SEND_COMPLETE)
|
||||
{
|
||||
if (client->get_headers("Connection") == "close")
|
||||
_close_client(client->fd);
|
||||
if (client->get_rq_headers("Connection") == "close")
|
||||
_close_client(client->get_cl_fd());
|
||||
else
|
||||
{
|
||||
_epoll_update(client->fd, EPOLLIN, EPOLL_CTL_MOD);
|
||||
_epoll_update(client->get_cl_fd(), EPOLLIN, EPOLL_CTL_MOD);
|
||||
client->clear();
|
||||
}
|
||||
}
|
||||
@@ -45,11 +45,11 @@ int Webserv::_send_response(Client *client)
|
||||
_error_html_response(client);
|
||||
|
||||
std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG
|
||||
ret = ::send(client->fd, client->response.c_str(), client->response.size(), 0);
|
||||
ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0);
|
||||
if (ret == -1)
|
||||
{
|
||||
std::perror("err send()");
|
||||
std::cerr << "client.fd =" << client->fd << "\n"; // DEBUG
|
||||
std::cerr << "client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
|
||||
return SEND_CLOSE;
|
||||
}
|
||||
std::cerr << "ret send() = " << ret << "\n"; // DEBUG
|
||||
@@ -61,7 +61,7 @@ void Webserv::_append_base_headers(Client *client)
|
||||
{
|
||||
client->response.append("Server: Webserv/0.1" CRLF);
|
||||
|
||||
if (client->get_headers("Connection") == "close")
|
||||
if (client->get_rq_headers("Connection") == "close")
|
||||
client->response.append("Connection: close" CRLF);
|
||||
else
|
||||
client->response.append("Connection: keep-alive" CRLF);
|
||||
@@ -70,7 +70,7 @@ void Webserv::_append_base_headers(Client *client)
|
||||
void Webserv::_construct_response(Client *client)
|
||||
{
|
||||
// TODO : Move this in read(), stop read if content too large
|
||||
if (client->get_body().size() > client->assigned_server->client_body_limit)
|
||||
if (client->get_rq_body().size() > client->assigned_server->client_body_limit)
|
||||
{
|
||||
client->status = 413;
|
||||
return;
|
||||
@@ -83,7 +83,7 @@ void Webserv::_construct_response(Client *client)
|
||||
client->response.append(client->assigned_location->redirect_uri);
|
||||
client->response.append(CRLF);
|
||||
} */
|
||||
if (client->get_path().find("redirect_test") != std::string::npos) // Test block
|
||||
if (client->get_rq_abs_path().find("redirect_test") != std::string::npos) // Test block
|
||||
{ // Weird behavior. The web browser seems to wait for a complete response until timeout.
|
||||
// (for codes 301, 302, 303, 307, and 308)
|
||||
client->status = 307;
|
||||
@@ -100,13 +100,13 @@ void Webserv::_process_method(Client *client)
|
||||
{
|
||||
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
|
||||
std::cerr << "allow_methods = " << client->assigned_location->allow_methods << "\n"; // debug
|
||||
if (client->get_method() == UNKNOWN)
|
||||
if (client->get_rq_method() == UNKNOWN)
|
||||
{
|
||||
client->status = 501;
|
||||
}
|
||||
else if (client->assigned_location->allow_methods & client->get_method())
|
||||
else if (client->assigned_location->allow_methods & client->get_rq_method())
|
||||
{
|
||||
switch (client->get_method())
|
||||
switch (client->get_rq_method())
|
||||
{
|
||||
case (GET):
|
||||
_get(client); break;
|
||||
@@ -181,14 +181,14 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
|
||||
TODO : test it
|
||||
*/
|
||||
|
||||
std::string &server_name = client->get_headers("Host");
|
||||
std::string const &server_name = client->get_rq_headers("Host");
|
||||
std::vector<ServerConfig>::iterator it = _servers.begin();
|
||||
std::vector<ServerConfig>::iterator default_server = _servers.end();
|
||||
|
||||
while (it != _servers.end())
|
||||
{
|
||||
if (it->host == client->lsocket->host
|
||||
&& it->port == client->lsocket->port)
|
||||
if (it->host == client->get_cl_lsocket()->host
|
||||
&& it->port == client->get_cl_lsocket()->port)
|
||||
{
|
||||
if ( std::find(it->server_name.begin(), it->server_name.end(), server_name) != it->server_name.end() )
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user