update http proxy lib.
This commit is contained in:
parent
80ed62b4c7
commit
52b593ce63
@ -1,12 +1,12 @@
|
|||||||
#include "TemplateMatchs.h"
|
#include "TemplateMatchs.h"
|
||||||
|
|
||||||
TemplateMatchStorageBase::const_reference TemplateMatchStorageBase::at(boost::urls::string_view id) const {
|
TemplateMatchStorageBase::const_reference TemplateMatchStorageBase::at(boost::core::string_view id) const {
|
||||||
for (std::size_t i = 0; i < size(); ++i) {
|
for (std::size_t i = 0; i < size(); ++i) {
|
||||||
if (ids()[i] == id) return matches()[i];
|
if (ids()[i] == id) return matches()[i];
|
||||||
}
|
}
|
||||||
boost::throw_exception(std::out_of_range(""));
|
boost::throw_exception(std::out_of_range(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateMatchStorageBase::const_reference TemplateMatchStorageBase::operator[](boost::urls::string_view id) const {
|
TemplateMatchStorageBase::const_reference TemplateMatchStorageBase::operator[](boost::core::string_view id) const {
|
||||||
return at(id);
|
return at(id);
|
||||||
}
|
}
|
||||||
|
@ -5,37 +5,37 @@
|
|||||||
|
|
||||||
class TemplateMatchStorageBase {
|
class TemplateMatchStorageBase {
|
||||||
public:
|
public:
|
||||||
using const_reference = boost::urls::string_view const &;
|
using const_reference = boost::core::string_view const &;
|
||||||
|
|
||||||
virtual boost::urls::string_view *matches() = 0;
|
virtual boost::core::string_view *matches() = 0;
|
||||||
virtual const boost::urls::string_view *matches() const = 0;
|
virtual const boost::core::string_view *matches() const = 0;
|
||||||
|
|
||||||
virtual boost::urls::string_view *ids() = 0;
|
virtual boost::core::string_view *ids() = 0;
|
||||||
virtual const boost::urls::string_view *ids() const = 0;
|
virtual const boost::core::string_view *ids() const = 0;
|
||||||
virtual std::size_t size() const = 0;
|
virtual std::size_t size() const = 0;
|
||||||
virtual void resize(std::size_t) = 0;
|
virtual void resize(std::size_t) = 0;
|
||||||
|
|
||||||
const_reference at(boost::urls::string_view id) const;
|
const_reference at(boost::core::string_view id) const;
|
||||||
|
|
||||||
const_reference operator[](boost::urls::string_view id) const;
|
const_reference operator[](boost::core::string_view id) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::size_t N = 20>
|
template <std::size_t N = 20>
|
||||||
class TemplateMatchStorage : public TemplateMatchStorageBase {
|
class TemplateMatchStorage : public TemplateMatchStorageBase {
|
||||||
public:
|
public:
|
||||||
boost::urls::string_view *matches() final {
|
boost::core::string_view *matches() final {
|
||||||
return m_matches;
|
return m_matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const boost::urls::string_view *matches() const final {
|
virtual const boost::core::string_view *matches() const final {
|
||||||
return m_matches;
|
return m_matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::urls::string_view *ids() final {
|
boost::core::string_view *ids() final {
|
||||||
return m_ids;
|
return m_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::urls::string_view *ids() const final {
|
const boost::core::string_view *ids() const final {
|
||||||
return m_ids;
|
return m_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::urls::string_view m_matches[N];
|
boost::core::string_view m_matches[N];
|
||||||
boost::urls::string_view m_ids[N];
|
boost::core::string_view m_ids[N];
|
||||||
std::size_t m_size;
|
std::size_t m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ boost::urls::result<TemplateSegmentRule::value_type> TemplateSegmentRule::parse(
|
|||||||
++iterator;
|
++iterator;
|
||||||
auto rightBraces = boost::urls::grammar::find_if(iterator, end, boost::urls::grammar::lut_chars('}'));
|
auto rightBraces = boost::urls::grammar::find_if(iterator, end, boost::urls::grammar::lut_chars('}'));
|
||||||
if (rightBraces != end) {
|
if (rightBraces != end) {
|
||||||
boost::urls::string_view segment(iterator, rightBraces);
|
boost::core::string_view segment(iterator, rightBraces);
|
||||||
static constexpr auto modifiers_cs = boost::urls::grammar::lut_chars("?*+");
|
static constexpr auto modifiers_cs = boost::urls::grammar::lut_chars("?*+");
|
||||||
static constexpr auto id_rule = boost::urls::grammar::tuple_rule(
|
static constexpr auto id_rule = boost::urls::grammar::tuple_rule(
|
||||||
boost::urls::grammar::optional_rule(boost::urls::detail::arg_id_rule),
|
boost::urls::grammar::optional_rule(boost::urls::detail::arg_id_rule),
|
||||||
@ -24,7 +24,7 @@ boost::urls::result<TemplateSegmentRule::value_type> TemplateSegmentRule::parse(
|
|||||||
if (segment.empty() || boost::urls::grammar::parse(segment, id_rule)) {
|
if (segment.empty() || boost::urls::grammar::parse(segment, id_rule)) {
|
||||||
isTemplate = true;
|
isTemplate = true;
|
||||||
iterator = rightBraces + 1;
|
iterator = rightBraces + 1;
|
||||||
ret.m_string = boost::urls::string_view(it0, rightBraces + 1);
|
ret.m_string = boost::core::string_view(it0, rightBraces + 1);
|
||||||
ret.m_isLiteral = false;
|
ret.m_isLiteral = false;
|
||||||
if (segment.ends_with('?'))
|
if (segment.ends_with('?'))
|
||||||
ret.modifier = TemplateSegment::Modifier::Optional;
|
ret.modifier = TemplateSegment::Modifier::Optional;
|
||||||
@ -65,16 +65,16 @@ bool TemplateSegment::hasModifier() const {
|
|||||||
return !m_isLiteral && modifier != Modifier::None;
|
return !m_isLiteral && modifier != Modifier::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::urls::string_view TemplateSegment::id() const {
|
boost::core::string_view TemplateSegment::id() const {
|
||||||
BOOST_ASSERT(!isLiteral());
|
BOOST_ASSERT(!isLiteral());
|
||||||
boost::urls::string_view r = {m_string};
|
boost::core::string_view r = {m_string};
|
||||||
r.remove_prefix(1);
|
r.remove_prefix(1);
|
||||||
r.remove_suffix(1);
|
r.remove_suffix(1);
|
||||||
if (r.ends_with('?') || r.ends_with('+') || r.ends_with('*')) r.remove_suffix(1);
|
if (r.ends_with('?') || r.ends_with('+') || r.ends_with('*')) r.remove_suffix(1);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::urls::string_view TemplateSegment::string() const {
|
boost::core::string_view TemplateSegment::string() const {
|
||||||
return m_string;
|
return m_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ public:
|
|||||||
bool isPlus() const;
|
bool isPlus() const;
|
||||||
bool isOptional() const;
|
bool isOptional() const;
|
||||||
bool hasModifier() const;
|
bool hasModifier() const;
|
||||||
boost::urls::string_view id() const;
|
boost::core::string_view id() const;
|
||||||
boost::urls::string_view string() const;
|
boost::core::string_view string() const;
|
||||||
bool match(boost::urls::pct_string_view segement) const;
|
bool match(boost::urls::pct_string_view segement) const;
|
||||||
bool operator==(const TemplateSegment &other) const;
|
bool operator==(const TemplateSegment &other) const;
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Resource *find(boost::urls::segments_encoded_view path, TemplateMatchStorageBase &matches) const noexcept {
|
const Resource *find(boost::urls::segments_encoded_view path, TemplateMatchStorageBase &matches) const noexcept {
|
||||||
boost::urls::string_view *matches_it = matches.matches();
|
boost::core::string_view *matches_it = matches.matches();
|
||||||
boost::urls::string_view *ids_it = matches.ids();
|
boost::core::string_view *ids_it = matches.ids();
|
||||||
AnyResource const *p = findImpl(path, matches_it, ids_it);
|
AnyResource const *p = findImpl(path, matches_it, ids_it);
|
||||||
if (p) {
|
if (p) {
|
||||||
BOOST_ASSERT(matches_it >= matches.matches());
|
BOOST_ASSERT(matches_it >= matches.matches());
|
||||||
|
@ -8,7 +8,7 @@ UrlRouterPrivate::UrlRouterPrivate() {
|
|||||||
m_nodes.push_back(SegementNode{});
|
m_nodes.push_back(SegementNode{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void UrlRouterPrivate::insertImpl(boost::urls::string_view pattern, const std::shared_ptr<AnyResource> &resource) {
|
void UrlRouterPrivate::insertImpl(boost::core::string_view pattern, const std::shared_ptr<AnyResource> &resource) {
|
||||||
if (pattern.starts_with("/")) pattern.remove_prefix(1);
|
if (pattern.starts_with("/")) pattern.remove_prefix(1);
|
||||||
auto segements = boost::urls::grammar::parse(pattern, templatePathRule);
|
auto segements = boost::urls::grammar::parse(pattern, templatePathRule);
|
||||||
if (!segements) {
|
if (!segements) {
|
||||||
@ -19,7 +19,7 @@ void UrlRouterPrivate::insertImpl(boost::urls::string_view pattern, const std::s
|
|||||||
auto currentNode = &m_nodes.front();
|
auto currentNode = &m_nodes.front();
|
||||||
int level = 0;
|
int level = 0;
|
||||||
while (iterator != end) {
|
while (iterator != end) {
|
||||||
boost::urls::string_view segement = (*iterator).string();
|
boost::core::string_view segement = (*iterator).string();
|
||||||
if (segement == ".") {
|
if (segement == ".") {
|
||||||
++iterator;
|
++iterator;
|
||||||
continue;
|
continue;
|
||||||
@ -80,8 +80,8 @@ void UrlRouterPrivate::insertImpl(boost::urls::string_view pattern, const std::s
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AnyResource *UrlRouterPrivate::findImpl(boost::urls::segments_encoded_view path,
|
const AnyResource *UrlRouterPrivate::findImpl(boost::urls::segments_encoded_view path,
|
||||||
boost::urls::string_view *&matches,
|
boost::core::string_view *&matches,
|
||||||
boost::urls::string_view *&ids) const noexcept {
|
boost::core::string_view *&ids) const noexcept {
|
||||||
if (path.empty()) path = boost::urls::segments_encoded_view("./");
|
if (path.empty()) path = boost::urls::segments_encoded_view("./");
|
||||||
const SegementNode *p = tryMatch(path.begin(), path.end(), &m_nodes.front(), 0, matches, ids);
|
const SegementNode *p = tryMatch(path.begin(), path.end(), &m_nodes.front(), 0, matches, ids);
|
||||||
if (p) return p->resource.get();
|
if (p) return p->resource.get();
|
||||||
@ -91,8 +91,8 @@ const AnyResource *UrlRouterPrivate::findImpl(boost::urls::segments_encoded_view
|
|||||||
const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_base::const_iterator it,
|
const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_base::const_iterator it,
|
||||||
boost::urls::segments_encoded_base::const_iterator end,
|
boost::urls::segments_encoded_base::const_iterator end,
|
||||||
const SegementNode *current, int level,
|
const SegementNode *current, int level,
|
||||||
boost::urls::string_view *&matches,
|
boost::core::string_view *&matches,
|
||||||
boost::urls::string_view *&ids) const {
|
boost::core::string_view *&ids) const {
|
||||||
while (it != end) {
|
while (it != end) {
|
||||||
boost::urls::pct_string_view s = *it;
|
boost::urls::pct_string_view s = *it;
|
||||||
if (*s == ".") {
|
if (*s == ".") {
|
||||||
@ -220,7 +220,7 @@ const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_bas
|
|||||||
while (start != first) {
|
while (start != first) {
|
||||||
r = tryMatch(start, end, &child, level, matches, ids);
|
r = tryMatch(start, end, &child, level, matches, ids);
|
||||||
if (r) {
|
if (r) {
|
||||||
boost::urls::string_view prev = *std::prev(start);
|
boost::core::string_view prev = *std::prev(start);
|
||||||
*matches0 = {matches0->data(), prev.data() + prev.size()};
|
*matches0 = {matches0->data(), prev.data() + prev.size()};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -255,8 +255,8 @@ const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_bas
|
|||||||
|
|
||||||
const SegementNode *UrlRouterPrivate::findOptionalResource(const SegementNode *root,
|
const SegementNode *UrlRouterPrivate::findOptionalResource(const SegementNode *root,
|
||||||
const std::vector<SegementNode> &ns,
|
const std::vector<SegementNode> &ns,
|
||||||
boost::urls::string_view *&matches,
|
boost::core::string_view *&matches,
|
||||||
boost::urls::string_view *&ids) {
|
boost::core::string_view *&ids) {
|
||||||
BOOST_ASSERT(root);
|
BOOST_ASSERT(root);
|
||||||
if (root->resource) return root;
|
if (root->resource) return root;
|
||||||
BOOST_ASSERT(!root->childIndexes.empty());
|
BOOST_ASSERT(!root->childIndexes.empty());
|
||||||
|
@ -45,16 +45,16 @@ public:
|
|||||||
class UrlRouterPrivate {
|
class UrlRouterPrivate {
|
||||||
public:
|
public:
|
||||||
UrlRouterPrivate();
|
UrlRouterPrivate();
|
||||||
void insertImpl(boost::urls::string_view pattern, const std::shared_ptr<AnyResource> &resource);
|
void insertImpl(boost::core::string_view pattern, const std::shared_ptr<AnyResource> &resource);
|
||||||
const AnyResource *findImpl(boost::urls::segments_encoded_view path, boost::urls::string_view *&matches,
|
const AnyResource *findImpl(boost::urls::segments_encoded_view path, boost::core::string_view *&matches,
|
||||||
boost::urls::string_view *&ids) const noexcept;
|
boost::core::string_view *&ids) const noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SegementNode const *tryMatch(boost::urls::segments_encoded_view::const_iterator it,
|
SegementNode const *tryMatch(boost::urls::segments_encoded_view::const_iterator it,
|
||||||
boost::urls::segments_encoded_view::const_iterator end, const SegementNode *current,
|
boost::urls::segments_encoded_view::const_iterator end, const SegementNode *current,
|
||||||
int level, boost::urls::string_view *&matches, boost::urls::string_view *&ids) const;
|
int level, boost::core::string_view *&matches, boost::core::string_view *&ids) const;
|
||||||
static SegementNode const *findOptionalResource(const SegementNode *root, std::vector<SegementNode> const &ns,
|
static SegementNode const *findOptionalResource(const SegementNode *root, std::vector<SegementNode> const &ns,
|
||||||
boost::urls::string_view *&matches, boost::urls::string_view *&ids);
|
boost::core::string_view *&matches, boost::core::string_view *&ids);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<SegementNode> m_nodes;
|
std::vector<SegementNode> m_nodes;
|
||||||
|
Loading…
Reference in New Issue
Block a user