mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
use local request parser
This commit is contained in:
parent
4da1e4d9c2
commit
75300eb45e
7 changed files with 82 additions and 87 deletions
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue