coyote/servehelper.h

32 lines
1.6 KiB
C
Raw Normal View History

2023-11-22 08:39:24 +00:00
#pragma once
#include <optional>
#include <httplib/httplib.h>
#include "blankie/serializer.h"
2023-12-02 13:50:33 +00:00
#include "lxb_wrapper.h"
2023-11-23 06:05:17 +00:00
struct Post; // forward declaration from models.h
2023-11-23 00:16:56 +00:00
struct Emoji; // forward declaration from models.h
2023-11-29 11:36:52 +00:00
class CurlUrl; // forward declaration from curlu_wrapper.h
2023-11-22 08:39:24 +00:00
using Element = blankie::html::Element;
using Node = blankie::html::Node;
using Nodes = std::vector<Node>;
void serve(const httplib::Request& req, httplib::Response& res, std::string title, Element element, Nodes extra_head = {});
void serve_error(const httplib::Request& req, httplib::Response& res,
std::string title, std::optional<std::string> subtitle = std::nullopt, std::optional<std::string> info = std::nullopt);
void serve_redirect(const httplib::Request& req, httplib::Response& res, std::string url, bool permanent = false);
2023-11-29 11:36:52 +00:00
bool starts_with(const CurlUrl& url, const CurlUrl& base);
2023-11-22 08:39:24 +00:00
std::string get_origin(const httplib::Request& req);
std::string proxy_mastodon_url(const httplib::Request& req, const std::string& url_str);
bool should_send_304(const httplib::Request& req, uint64_t hash);
2023-11-22 23:27:44 +00:00
2023-11-23 23:46:47 +00:00
Element serialize_post(const httplib::Request& req, const std::string& server, const Post& post, bool pinned = false, bool main_post = false);
2023-11-23 06:05:17 +00:00
2023-12-02 13:50:33 +00:00
std::string get_text_content(lxb_dom_node_t* child);
std::string get_text_content(blankie::html::HTMLString str);
2023-11-23 00:16:56 +00:00
blankie::html::HTMLString preprocess_html(const httplib::Request& req, const std::string& domain_name, const std::vector<Emoji>& emojis, const blankie::html::HTMLString& str);
blankie::html::HTMLString preprocess_html(const httplib::Request& req, const std::vector<Emoji>& emojis, const std::string& str);