62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
|
|
#ifndef CLIENT_HPP
|
|
# define CLIENT_HPP
|
|
|
|
# include <iostream>
|
|
# include <string>
|
|
# include <map>
|
|
# include <vector>
|
|
# include "utils.hpp"
|
|
|
|
struct Request
|
|
{
|
|
http_method method;
|
|
std::string path;
|
|
std::string version;
|
|
std::map<std::string, std::string> headers;
|
|
std::string body;
|
|
};
|
|
|
|
# define MAX_FILESIZE 1000000 // (1Mo)
|
|
class Client
|
|
{
|
|
public:
|
|
Client();
|
|
~Client();
|
|
//Client(Client const &src);
|
|
//Client &operator=(Client const &rhs);
|
|
|
|
int fd;
|
|
std::string raw_request;
|
|
std::string response;
|
|
static char buf[MAX_FILESIZE+1];
|
|
size_t body_size;
|
|
unsigned int status;
|
|
listen_socket *lsocket;
|
|
|
|
// const functions ?
|
|
http_method get_method();
|
|
std::string &get_path();
|
|
std::string &get_version();
|
|
std::string &get_body();
|
|
std::string &get_headers(const std::string &key);
|
|
|
|
void parse_request();
|
|
void clear();
|
|
void clear_request();
|
|
|
|
private:
|
|
struct Request _request;
|
|
|
|
void _parse_request_line( std::string rline );
|
|
void _parse_request_headers( std::vector<std::string> list );
|
|
void _parse_request_body( size_t pos );
|
|
|
|
};
|
|
|
|
bool operator==(const Client& lhs, const Client& rhs);
|
|
bool operator==(const Client& lhs, int fd);
|
|
bool operator==(int fd, const Client& rhs);
|
|
|
|
#endif
|