CRLF macro

This commit is contained in:
LuckyLaszlo
2022-08-04 14:45:16 +02:00
parent 0026106bf6
commit a9ada4cb28
3 changed files with 13 additions and 9 deletions

View File

@@ -35,7 +35,7 @@ void Client::parse_request()
std::vector<std::string> list; std::vector<std::string> list;
size_t pos; size_t pos;
pos = (raw_request).find("\r\n\r\n"); pos = (raw_request).find(CRLF CRLF);
sub = (raw_request).substr(0, pos); sub = (raw_request).substr(0, pos);
list = split(sub, '\n'); list = split(sub, '\n');
// request_line // request_line

View File

@@ -7,6 +7,10 @@
# include <sstream> # include <sstream>
# include <cstdlib> // atoi # include <cstdlib> // atoi
# define CR "\r"
# define LF "\n"
# define CRLF CR LF
// enum http_method // enum http_method
// { // {
// UNKNOWN = 0b00000000, // UNKNOWN = 0b00000000,

View File

@@ -43,12 +43,12 @@ void Webserv::_send_response(Client *client, ServerConfig &server)
void Webserv::_append_base_headers(Client *client) 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") if (client->get_headers("Connection") == "close")
client->response.append("Connection: close\r\n"); client->response.append("Connection: close" CRLF);
else else
client->response.append("Connection: keep-alive\r\n"); client->response.append("Connection: keep-alive" CRLF);
} }
void Webserv::_construct_response(Client *client, ServerConfig &server) 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->status = 405;
client->response.append("Allow: "); client->response.append("Allow: ");
client->response.append(::http_methods_to_str(allow_methods)); 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/1.1 ");
status_line.append(_http_status[client->status]); status_line.append(_http_status[client->status]);
status_line.append("\r\n"); status_line.append(CRLF);
client->response.insert(0, status_line); 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 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. 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: "); client->response.append("Content-Length: ");
std::string tmp = ::itos(body_size); std::string tmp = ::itos(body_size);
client->response.append(tmp); 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); client->response.append(body);
} }