Added sending css file. Broke up some pieces of code, so now the ServerUtil is a bit more clean now.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#ifndef DATATYPE_H
|
||||
#define DATATYPE_H
|
||||
|
||||
enum data_type {
|
||||
HTML,
|
||||
CSS,
|
||||
IMAGE
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,6 @@ using namespace std;
|
||||
|
||||
struct FileUtils {
|
||||
static bool fileExists(const char *path);
|
||||
static char* getFiles(const char *path);
|
||||
};
|
||||
|
||||
#endif
|
||||
+62
-3
@@ -12,12 +12,71 @@
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include "../include/DataType.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ServerUtils {
|
||||
static void serve(map<string, map<string, int>> wordwordFrequencies);
|
||||
static void process_request(int client_fd, map<string, map<string, int>> wordwordFrequencies);
|
||||
class ServerUtils {
|
||||
public:
|
||||
static void serve();
|
||||
private:
|
||||
static void process_request(int client_fd);
|
||||
static void send_header(int client_fd, data_type type);
|
||||
static void send_chunked_html(int client_fd, unsigned int hash);
|
||||
static void send_chunked_css(int client_fd);
|
||||
static void send_data(int client_fd, string data);
|
||||
};
|
||||
|
||||
const string HTML_RESPONSE_HEADER =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: text/html; charset=utf-8\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Cache-control: max-age=12000\r\n"
|
||||
"Connection: close\r\n\r\n";
|
||||
|
||||
const string CSS_RESPONSE_HEADER =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: text/css; charset=utf-8\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Cache-control: max-age=12000\r\n"
|
||||
"Connection: close\r\n\r\n";
|
||||
|
||||
const string PNG_RESPONSE_HEADER =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: text/png; charset=utf-8\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Cache-control: max-age=12000\r\n"
|
||||
"Connection: close\r\n\r\n";
|
||||
|
||||
const string HTML_BEGINNING =
|
||||
"<!DOCTYPE html>\n<html><head>\r\n"
|
||||
"<title>Drip</title>\r\n"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\r\n"
|
||||
"<link rel=\"icon\" href=\"favicon.png\"\r\n"
|
||||
"</head><body>\r\n";
|
||||
|
||||
const string HTML_END = "</body></html>\r\n";
|
||||
|
||||
const string HTML_NAV =
|
||||
"<div class=\"flex flex-col min-h-screen bg-var_background\">\r\n"
|
||||
"<header class=\"flex justify-center\">\r\n"
|
||||
"<nav class=\"pt-10 text-2xl flex place-items-center\">\r\n"
|
||||
"<a class=\"underline\" href=\"/\">Home</a>\r\n"
|
||||
"</nav>\r\n"
|
||||
"</header>\r\n";
|
||||
|
||||
const string HTML_MAIN_1 =
|
||||
"<main class=\"pt-10 flex justify-center grow\">\r\n"
|
||||
"<div class=\"w-full max-w-screen-lg px-4\">\r\n";
|
||||
|
||||
const string HTML_MAIN_2 =
|
||||
"</div>\r\n"
|
||||
"</main>\r\n";
|
||||
|
||||
const string HTML_FOOTER =
|
||||
"<footer class=\"flex justify-center pt-10 mt-10 pb-2\">\r\n"
|
||||
"<h5>Author: <a class=\"underline\" href=\"https://proxy.rbwr.dk/\">Dr. Lol Man 365</a></h5>\r\n"
|
||||
"</footer>\r\n"
|
||||
"</div>\r\n";
|
||||
|
||||
#endif
|
||||
+6
-4
@@ -6,16 +6,18 @@
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include "../include/DataType.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct WordUtils {
|
||||
static map<string, map<string, int>> load_data(const char *path);
|
||||
static map<string, map<string, int>> load_data(const string& path);
|
||||
static vector<string> load_css(const string& path);
|
||||
static vector<string> predict_next_word(const string& input, const map<string, map<string, int>>& word_frequencies, size_t count);
|
||||
static string load_file(const char *path);
|
||||
static vector<string> split_string(const string& input, const char *delimiters);
|
||||
static string load_file(const string& path);
|
||||
static vector<string> split_string(const string& input, data_type type);
|
||||
static string extract_url(const string& input);
|
||||
static vector<string> create_tag(const map<string, map<string, int>>& word_frequencies, unsigned int hash);
|
||||
static string create_tag(const map<string, map<string, int>>& word_frequencies, const char& hash);
|
||||
static unsigned int hash_url(const string& input);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user