Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
 
Loading...
Searching...
No Matches
url.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <format>
4#include <string>
5#include <vector>
6#include <sstream>
7
8#include <absl/container/flat_hash_map.h>
9
10namespace dcn::http
11{
12 class URL
13 {
14 public:
15 URL() = default;
16 URL(const std::string & url);
17 URL(std::string && url);
18 URL(const char * url);
19
20 URL(const URL &) = default;
21 URL(URL &&) = default;
22 ~URL() = default;
23
24 URL & operator=(const URL &) = default;
25 URL & operator=(URL &&) = default;
26
27 bool operator==(const URL& other) const;
28
33 std::string getFullPath() const;
34
39 std::string getPathModule() const;
40
45 std::string getPathInfo() const;
46
51 std::string getQuery() const;
52
53 private:
54 std::string _url;
55 };
56
65 template <typename H>
66 inline H AbslHashValue(H h, const URL & url) {
67 return H::combine(std::move(h), url.getFullPath());
68 }
69
70 std::vector<std::string> splitPathSegments(const std::string path);
71 absl::flat_hash_map<std::string, std::string> splitQuerySegments(const std::string& query);
72}
73
74template <>
75struct std::formatter<dcn::http::URL> : std::formatter<std::string> {
76 auto format(const dcn::http::URL & url, format_context& ctx) const {
77 return formatter<string>::format(
78 std::format("{}", url.getFullPath()), ctx);
79 }
80};
Definition url.hpp:13
URL & operator=(URL &&)=default
bool operator==(const URL &other) const
Definition url.cpp:21
std::string getPathInfo() const
Returns the path info of the URL.
Definition url.cpp:52
~URL()=default
std::string getQuery() const
Returns the query string of the URL.
Definition url.cpp:31
URL & operator=(const URL &)=default
std::string getPathModule() const
Returns the path module of the URL.
Definition url.cpp:42
std::string getFullPath() const
Returns the full path of the URL, including the query string.
Definition url.cpp:26
URL()=default
URL(URL &&)=default
URL(const URL &)=default
Definition http.hpp:16
H AbslHashValue(H h, const URL &url)
Combines hash values for a RouteKey object.
Definition url.hpp:66
std::vector< std::string > splitPathSegments(const std::string path)
Definition url.cpp:65
absl::flat_hash_map< std::string, std::string > splitQuerySegments(const std::string &query)
Definition url.cpp:86
Definition decentralised_art.hpp:30
auto format(const dcn::http::URL &url, format_context &ctx) const
Definition url.hpp:76