72 lines
2.5 KiB
C++
72 lines
2.5 KiB
C++
#ifndef SERVERUTILS_H
|
|
#define SERVERUTILS_H
|
|
|
|
#include <string>
|
|
#include <chrono>
|
|
#include "../include/DataType.h"
|
|
#include "../include/Track.h"
|
|
#include "../include/ConcurrentQueue.h"
|
|
|
|
using namespace std;
|
|
|
|
class ServerUtils {
|
|
public:
|
|
static void serve(shared_ptr<ConcurrentQueue<Track>> cq_track);
|
|
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, size_t hash);
|
|
static void send_chunked_css(int client_fd);
|
|
static void send_data(int client_fd, const string& data);
|
|
static void send_image(int client_fd, const string& path, image_type type);
|
|
static size_t send_all(int client_fd, const char* data, size_t length);
|
|
static uint32_t get_ip_2(int client_fd);
|
|
};
|
|
|
|
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 HTML_BEGINNING =
|
|
"<!DOCTYPE html>\n<html><head>\r\n"
|
|
"<title>Drip</title>\r\n"
|
|
"<link rel=\"preload\" href=\"style.css\" as=\"style\" />\r\n"
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\r\n"
|
|
"<link rel=\"icon\" type=\"image/png\" 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 |