added colors, for print_special
+ renamed client's public function parse_request() into parse_request_headers()
This commit is contained in:
@@ -75,22 +75,17 @@ Client & Client::operator=( Client const & rhs )
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
|
||||
// https://www.ibm.com/docs/en/cics-ts/5.3?topic=protocol-http-requests
|
||||
// https://www.tutorialspoint.com/http/http_requests.htm
|
||||
void Client::parse_request(std::vector<ServerConfig> &servers)
|
||||
void Client::parse_request_headers(std::vector<ServerConfig> &servers)
|
||||
{
|
||||
clear_request(); // not mandatory
|
||||
// debug
|
||||
print_client("before");
|
||||
|
||||
_parse_request_line();
|
||||
// debug
|
||||
print_client("first line");
|
||||
|
||||
if (status)
|
||||
return;
|
||||
_parse_request_headers();
|
||||
_parse_request_fields();
|
||||
// debug
|
||||
print_client("headers");
|
||||
|
||||
if (status)
|
||||
return;
|
||||
assigned_server = ::_determine_process_server(this, servers);
|
||||
@@ -174,7 +169,7 @@ void Client::print_client(std::string message)
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
|
||||
std::cout << "\n=== DEBUG PRINT CLIENT ===\n";
|
||||
std::cout << "\n" << message << ":\n----------\n" << "raw_request:\n__\n";
|
||||
std::cout << "\n" << message << ":----------\n\n" << "raw_request:\n__\n";
|
||||
::print_special(raw_request);
|
||||
std::cout << "\n__\n"
|
||||
<< "get_cl_fd() : [" << get_cl_fd() << "]\n"
|
||||
@@ -240,12 +235,6 @@ void Client::_parse_request_line()
|
||||
std::string raw_line;
|
||||
|
||||
raw_line = ::get_line(raw_request, 0, CRLF);
|
||||
|
||||
// DEBUG
|
||||
std::cout << "raw_line:[";
|
||||
::print_special(raw_line);
|
||||
std::cout << "]\n";
|
||||
|
||||
line = ::split_trim(raw_line, " ");
|
||||
if (line.size() != 3)
|
||||
{
|
||||
@@ -273,7 +262,7 @@ void Client::_parse_request_uri( std::string uri )
|
||||
_request.abs_path = uri.substr(0, pos);
|
||||
}
|
||||
|
||||
void Client::_parse_request_headers()
|
||||
void Client::_parse_request_fields()
|
||||
{
|
||||
std::string headers;
|
||||
size_t pos;
|
||||
|
||||
@@ -69,7 +69,7 @@ class Client
|
||||
std::string get_rq_script_info() const;
|
||||
std::string get_rq_headers(const std::string & key) const;
|
||||
|
||||
void parse_request(std::vector<ServerConfig> &servers);
|
||||
void parse_request_headers(std::vector<ServerConfig> &servers);
|
||||
void parse_request_body();
|
||||
void clear();
|
||||
void clear_request();
|
||||
@@ -86,7 +86,7 @@ class Client
|
||||
struct Request _request;
|
||||
|
||||
void _parse_request_line();
|
||||
void _parse_request_headers();
|
||||
void _parse_request_fields();
|
||||
void _parse_request_uri( std::string uri );
|
||||
void _parse_port_hostname(std::string host);
|
||||
|
||||
|
||||
25
srcs/colors.h
Normal file
25
srcs/colors.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef COLORS_H
|
||||
# define COLORS_H
|
||||
|
||||
# define GRAY "\e[0;30m"
|
||||
# define RED "\e[0;31m"
|
||||
# define GREEN "\e[0;32m"
|
||||
# define YELLOW "\e[0;33m"
|
||||
# define BLUE "\e[0;34m"
|
||||
# define PURPLE "\e[0;35m"
|
||||
# define CYAN "\e[0;36m"
|
||||
# define WHITE "\e[0;37m"
|
||||
|
||||
# define B_GRAY "\e[1;30m"
|
||||
# define B_RED "\e[1;31m"
|
||||
# define B_GREEN "\e[1;32m"
|
||||
# define B_YELLOW "\e[1;33m"
|
||||
# define B_BLUE "\e[1;34m"
|
||||
# define B_PURPLE "\e[1;35m"
|
||||
# define B_CYAN "\e[1;36m"
|
||||
# define B_WHITE "\e[1;37m"
|
||||
|
||||
# define RESET "\e[0m"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -284,9 +284,9 @@ void print_special(std::string str)
|
||||
{
|
||||
c = str[i];
|
||||
if (c == '\r')
|
||||
std::cout << "\\r";
|
||||
std::cout << YELLOW << "\\r" << RESET;
|
||||
else if (c == '\n')
|
||||
std::cout << "\\n" << "\n";
|
||||
std::cout << YELLOW << "\\n" << RESET << "\n";
|
||||
else
|
||||
std::cout << c;
|
||||
fflush(stdout);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# include <cctype> // tolower
|
||||
# include <algorithm> // transform
|
||||
# include <cstdio> // fflush
|
||||
# include "colors.h"
|
||||
|
||||
# define CR "\r"
|
||||
# define LF "\n"
|
||||
|
||||
@@ -56,7 +56,7 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
|
||||
if (client->raw_request.find(CRLF CRLF) != std::string::npos)
|
||||
{
|
||||
client->header_complete = true;
|
||||
client->parse_request(_servers);
|
||||
client->parse_request_headers(_servers);
|
||||
std::cerr << client->get_rq_method_str() << " " << client->get_rq_uri() << " " << client->get_rq_version() << "\n"; // DEBUG
|
||||
if (client->status)
|
||||
return READ_COMPLETE;
|
||||
|
||||
Reference in New Issue
Block a user