use local request parser

This commit is contained in:
yggverse 2024-08-15 16:15:26 +03:00
parent 4da1e4d9c2
commit 75300eb45e
7 changed files with 82 additions and 87 deletions

View file

@ -1,41 +0,0 @@
#include "url.hpp"
using namespace lib;
using namespace std;
Url::Url(
string subject
) {
smatch results;
static const regex pattern( // @TODO user:password@#fragment?
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
);
regex_search(
subject,
results,
pattern
);
scheme = results[2];
host = results[3];
port = results[5];
path = results[6];
query = results[8];
}
string Url::to_string()
{
string result;
if (!scheme.empty()) result += scheme + "://";
if (!host.empty()) result += host;
if (!port.empty()) result += ":" + port;
if (!path.empty()) result += "/" + path;
if (!query.empty()) result += "?" + query;
return result;
}
Url::~Url() = default;

View file

@ -1,29 +0,0 @@
#ifndef LIB_URL_HPP
#define LIB_URL_HPP
#include <regex>
#include <string>
namespace lib
{
class Url
{
public:
std::string scheme,
host,
port,
path,
query;
Url(
std::string subject
);
std::string to_string();
~Url();
};
}
#endif // LIB_URL_HPP