CRLF macro
This commit is contained in:
@@ -35,7 +35,7 @@ void Client::parse_request()
|
||||
std::vector<std::string> list;
|
||||
size_t pos;
|
||||
|
||||
pos = (raw_request).find("\r\n\r\n");
|
||||
pos = (raw_request).find(CRLF CRLF);
|
||||
sub = (raw_request).substr(0, pos);
|
||||
list = split(sub, '\n');
|
||||
// request_line
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
# include <sstream>
|
||||
# include <cstdlib> // atoi
|
||||
|
||||
# define CR "\r"
|
||||
# define LF "\n"
|
||||
# define CRLF CR LF
|
||||
|
||||
// enum http_method
|
||||
// {
|
||||
// UNKNOWN = 0b00000000,
|
||||
|
||||
@@ -43,12 +43,12 @@ void Webserv::_send_response(Client *client, ServerConfig &server)
|
||||
|
||||
void Webserv::_append_base_headers(Client *client)
|
||||
{
|
||||
client->response.append("Server: Webserv/0.1\r\n");
|
||||
client->response.append("Server: Webserv/0.1" CRLF);
|
||||
|
||||
if (client->get_headers("Connection") == "close")
|
||||
client->response.append("Connection: close\r\n");
|
||||
client->response.append("Connection: close" CRLF);
|
||||
else
|
||||
client->response.append("Connection: keep-alive\r\n");
|
||||
client->response.append("Connection: keep-alive" CRLF);
|
||||
}
|
||||
|
||||
void Webserv::_construct_response(Client *client, ServerConfig &server)
|
||||
@@ -94,7 +94,7 @@ void Webserv::_process_method(Client *client, ServerConfig &server, LocationConf
|
||||
client->status = 405;
|
||||
client->response.append("Allow: ");
|
||||
client->response.append(::http_methods_to_str(allow_methods));
|
||||
client->response.append("\r\n");
|
||||
client->response.append(CRLF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ void Webserv::_insert_status_line(Client *client)
|
||||
|
||||
status_line.append("HTTP/1.1 ");
|
||||
status_line.append(_http_status[client->status]);
|
||||
status_line.append("\r\n");
|
||||
status_line.append(CRLF);
|
||||
client->response.insert(0, status_line);
|
||||
}
|
||||
|
||||
@@ -195,14 +195,14 @@ void Webserv::_append_body(Client *client, const char *body, size_t body_size)
|
||||
http://nginx.org/en/docs/http/ngx_http_core_module.html#types
|
||||
Need to look "conf/mime.types" of nginx. Maybe make a map<> based on that.
|
||||
*/
|
||||
client->response.append("Content-Type: text/html; charset=UTF-8\r\n");
|
||||
client->response.append("Content-Type: text/html; charset=UTF-8" CRLF);
|
||||
|
||||
client->response.append("Content-Length: ");
|
||||
std::string tmp = ::itos(body_size);
|
||||
client->response.append(tmp);
|
||||
client->response.append("\r\n");
|
||||
client->response.append(CRLF);
|
||||
|
||||
client->response.append("\r\n");
|
||||
client->response.append(CRLF);
|
||||
client->response.append(body);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user