-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.h
34 lines (28 loc) · 1.07 KB
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef WEB_SERVER_HELPER_H
#define WEB_SERVER_HELPER_H
#include <iostream>
#include <unistd.h>
#include <sstream>
#include <optional>
#include <cstring>
#include <unordered_set>
#include <sys/stat.h>
#include <fcntl.h>
#include <memory>
#include "request.h"
#include "connection.h"
using std::string, std::stringstream, std::optional, std::unordered_set, std::memset, std::shared_ptr;
class helper {
public:
static string readline_from_connection(shared_ptr<connection> conn);
static void parse_header(shared_ptr<connection> conn, int conn_fd);
static void parse_body(shared_ptr<connection> conn, int conn_fd);
static optional<string> read_file_extension(const string& url);
static string get_file_type(const string& file_extensions);
static bool file_exist(const string& file_name, struct stat& file_stat);
static void set_non_block(const int fd);
private:
static void read_http_first_line(shared_ptr<connection> conn, int conn_fd);
static int read_one_char_from_connection(char& buff, shared_ptr<connection> conn);
};
#endif //WEB_SERVER_HELPER_H