Compare commits
No commits in common. "21f1245bf84fe5c561e20d27e6fdbd0b4d44e93b" and "bacb6d2fb30c3f4d2cc29f09bbd231b2bcb4689d" have entirely different histories.
21f1245bf8
...
bacb6d2fb3
|
@ -32,8 +32,5 @@ class URI {
|
||||||
void set_port(const std::string& port) { this->port = port; }
|
void set_port(const std::string& port) { this->port = port; }
|
||||||
|
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
|
|
||||||
static std::string decode(std::string text);
|
|
||||||
static std::string encode(std::string text);
|
|
||||||
};
|
};
|
||||||
} // namespace Rum::HTTP
|
} // namespace Rum::HTTP
|
|
@ -2,8 +2,6 @@
|
||||||
#include <rum/http/request.h>
|
#include <rum/http/request.h>
|
||||||
#if __cplusplus >= 202302L
|
#if __cplusplus >= 202302L
|
||||||
#include <format>
|
#include <format>
|
||||||
#else
|
|
||||||
#include <sstream>
|
|
||||||
#endif
|
#endif
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -21,15 +19,7 @@ Request::operator std::string() const {
|
||||||
cookie_string += "\t\t'" + cookie.first + "': '" + cookie.second + "'\n";
|
cookie_string += "\t\t'" + cookie.first + "': '" + cookie.second + "'\n";
|
||||||
}
|
}
|
||||||
#if __cplusplus < 202302L
|
#if __cplusplus < 202302L
|
||||||
std::stringstream text;
|
return "";
|
||||||
text << "Request{{\n"
|
|
||||||
<< "\tmethod: " << method << "\n"
|
|
||||||
<< "\t" << (std::string)uri << "\n"
|
|
||||||
<< "\theaders: \n"
|
|
||||||
<< headers_string << "\tcookies: \n"
|
|
||||||
<< cookie_string << "\tbody: '" << body << "'\n}}";
|
|
||||||
|
|
||||||
return text.str();
|
|
||||||
#else
|
#else
|
||||||
return std::vformat(
|
return std::vformat(
|
||||||
"Request{{\n"
|
"Request{{\n"
|
||||||
|
|
|
@ -2,11 +2,8 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sstream>
|
|
||||||
#if __cplusplus >= 202302L
|
#if __cplusplus >= 202302L
|
||||||
#include <format>
|
#include <format>
|
||||||
#else
|
|
||||||
#include <sstream>
|
|
||||||
#endif
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -18,18 +15,7 @@ URI::operator std::string() const {
|
||||||
query += "\t\t'" + param.first + "': '" + param.second + "'\n";
|
query += "\t\t'" + param.first + "': '" + param.second + "'\n";
|
||||||
}
|
}
|
||||||
#if __cplusplus < 202302L
|
#if __cplusplus < 202302L
|
||||||
std::stringstream text;
|
return "";
|
||||||
text << "URI{{"
|
|
||||||
<< "\n\tscheme: '" << scheme << "'"
|
|
||||||
<< "\n\tuser: '" << user << "'"
|
|
||||||
<< "\n\tpassword: '" << password << "'"
|
|
||||||
<< "\n\thost: '" << host << "'"
|
|
||||||
<< "\n\tport: '" << port << "'"
|
|
||||||
<< "\n\tpath: '" << path << "'"
|
|
||||||
<< "\n\tquery: \n"
|
|
||||||
<< query << "\n\tfragment: '" << fragment << "'\n}}";
|
|
||||||
|
|
||||||
return text.str();
|
|
||||||
#else
|
#else
|
||||||
return std::vformat(
|
return std::vformat(
|
||||||
"URI{{"
|
"URI{{"
|
||||||
|
@ -47,12 +33,12 @@ URI::operator std::string() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
URI::URI(const std::string& uri) {
|
URI::URI(const std::string& uri) {
|
||||||
std::regex uri_regex(R"((([\w\d]+):\/\/)?(([\w\d%]+)(:([\w\d%]+)?)@)?([\w\d\.]+)(:(\d+))?(\/?[\w\d%\.\/]+)?(\?([^#]+))?(\#([\w\d%]*))?)");
|
std::regex uri_regex(R"((([\w\d]+):\/\/)?(([\w\d]+)(:([\w\d]+)?)@)?([\w\d\.]+)(:(\d+))?(\/?[\w\d\.\/]+)?(\?([^#]+))?(\#([\w\d]*))?)");
|
||||||
|
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << uri_decoded << std::endl;
|
std::cout << uri << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (std::regex_match(uri.cbegin(), uri.cend(), match, uri_regex)) {
|
if (std::regex_match(uri.cbegin(), uri.cend(), match, uri_regex)) {
|
||||||
|
@ -62,18 +48,13 @@ URI::URI(const std::string& uri) {
|
||||||
|
|
||||||
MATCH(scheme, 2)
|
MATCH(scheme, 2)
|
||||||
MATCH(user, 4)
|
MATCH(user, 4)
|
||||||
user = decode(user);
|
|
||||||
MATCH(password, 6)
|
MATCH(password, 6)
|
||||||
password = decode(password);
|
|
||||||
MATCH(host, 7)
|
MATCH(host, 7)
|
||||||
MATCH(port, 9)
|
MATCH(port, 9)
|
||||||
MATCH(path, 10)
|
MATCH(path, 10)
|
||||||
path = decode(path);
|
|
||||||
std::string query;
|
std::string query;
|
||||||
MATCH(query, 12)
|
MATCH(query, 12)
|
||||||
query = decode(query);
|
|
||||||
MATCH(fragment, 14)
|
MATCH(fragment, 14)
|
||||||
fragment = decode(fragment);
|
|
||||||
|
|
||||||
std::stringstream parameters_string(query);
|
std::stringstream parameters_string(query);
|
||||||
std::string parameter;
|
std::string parameter;
|
||||||
|
@ -88,19 +69,4 @@ URI::URI(const std::string& uri) {
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string URI::decode(std::string text) {
|
|
||||||
std::regex encoded_regex(R"(%([\w\d]{2}))");
|
|
||||||
std::smatch match;
|
|
||||||
while (std::regex_search(text.cbegin(), text.cend(), match, encoded_regex)) {
|
|
||||||
char decoded = (char)std::stoi(match.str(1), 0, 16);
|
|
||||||
text = text.substr(0, match.position()) + decoded + text.substr(match.position() + 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
std::string URI::encode(std::string text) {
|
|
||||||
throw std::exception();
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
} // namespace Rum::HTTP
|
} // namespace Rum::HTTP
|
Loading…
Reference in New Issue