update http proxy lib.

This commit is contained in:
amass 2023-12-30 00:03:40 +08:00
parent 80ed62b4c7
commit 52b593ce63
7 changed files with 38 additions and 38 deletions

View File

@ -1,12 +1,12 @@
#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) {
if (ids()[i] == id) return matches()[i];
}
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);
}

View File

@ -5,37 +5,37 @@
class TemplateMatchStorageBase {
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 const boost::urls::string_view *matches() const = 0;
virtual boost::core::string_view *matches() = 0;
virtual const boost::core::string_view *matches() const = 0;
virtual boost::urls::string_view *ids() = 0;
virtual const boost::urls::string_view *ids() const = 0;
virtual boost::core::string_view *ids() = 0;
virtual const boost::core::string_view *ids() const = 0;
virtual std::size_t size() const = 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>
class TemplateMatchStorage : public TemplateMatchStorageBase {
public:
boost::urls::string_view *matches() final {
boost::core::string_view *matches() final {
return m_matches;
}
virtual const boost::urls::string_view *matches() const final {
virtual const boost::core::string_view *matches() const final {
return m_matches;
}
boost::urls::string_view *ids() final {
boost::core::string_view *ids() final {
return m_ids;
}
const boost::urls::string_view *ids() const final {
const boost::core::string_view *ids() const final {
return m_ids;
}
@ -47,8 +47,8 @@ public:
}
private:
boost::urls::string_view m_matches[N];
boost::urls::string_view m_ids[N];
boost::core::string_view m_matches[N];
boost::core::string_view m_ids[N];
std::size_t m_size;
};

View File

@ -16,7 +16,7 @@ boost::urls::result<TemplateSegmentRule::value_type> TemplateSegmentRule::parse(
++iterator;
auto rightBraces = boost::urls::grammar::find_if(iterator, end, boost::urls::grammar::lut_chars('}'));
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 id_rule = boost::urls::grammar::tuple_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)) {
isTemplate = true;
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;
if (segment.ends_with('?'))
ret.modifier = TemplateSegment::Modifier::Optional;
@ -65,16 +65,16 @@ bool TemplateSegment::hasModifier() const {
return !m_isLiteral && modifier != Modifier::None;
}
boost::urls::string_view TemplateSegment::id() const {
boost::core::string_view TemplateSegment::id() const {
BOOST_ASSERT(!isLiteral());
boost::urls::string_view r = {m_string};
boost::core::string_view r = {m_string};
r.remove_prefix(1);
r.remove_suffix(1);
if (r.ends_with('?') || r.ends_with('+') || r.ends_with('*')) r.remove_suffix(1);
return r;
}
boost::urls::string_view TemplateSegment::string() const {
boost::core::string_view TemplateSegment::string() const {
return m_string;
}

View File

@ -26,8 +26,8 @@ public:
bool isPlus() const;
bool isOptional() const;
bool hasModifier() const;
boost::urls::string_view id() const;
boost::urls::string_view string() const;
boost::core::string_view id() const;
boost::core::string_view string() const;
bool match(boost::urls::pct_string_view segement) const;
bool operator==(const TemplateSegment &other) const;

View File

@ -31,8 +31,8 @@ public:
}
const Resource *find(boost::urls::segments_encoded_view path, TemplateMatchStorageBase &matches) const noexcept {
boost::urls::string_view *matches_it = matches.matches();
boost::urls::string_view *ids_it = matches.ids();
boost::core::string_view *matches_it = matches.matches();
boost::core::string_view *ids_it = matches.ids();
AnyResource const *p = findImpl(path, matches_it, ids_it);
if (p) {
BOOST_ASSERT(matches_it >= matches.matches());

View File

@ -8,7 +8,7 @@ UrlRouterPrivate::UrlRouterPrivate() {
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);
auto segements = boost::urls::grammar::parse(pattern, templatePathRule);
if (!segements) {
@ -19,7 +19,7 @@ void UrlRouterPrivate::insertImpl(boost::urls::string_view pattern, const std::s
auto currentNode = &m_nodes.front();
int level = 0;
while (iterator != end) {
boost::urls::string_view segement = (*iterator).string();
boost::core::string_view segement = (*iterator).string();
if (segement == ".") {
++iterator;
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,
boost::urls::string_view *&matches,
boost::urls::string_view *&ids) const noexcept {
boost::core::string_view *&matches,
boost::core::string_view *&ids) const noexcept {
if (path.empty()) path = boost::urls::segments_encoded_view("./");
const SegementNode *p = tryMatch(path.begin(), path.end(), &m_nodes.front(), 0, matches, ids);
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,
boost::urls::segments_encoded_base::const_iterator end,
const SegementNode *current, int level,
boost::urls::string_view *&matches,
boost::urls::string_view *&ids) const {
boost::core::string_view *&matches,
boost::core::string_view *&ids) const {
while (it != end) {
boost::urls::pct_string_view s = *it;
if (*s == ".") {
@ -220,7 +220,7 @@ const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_bas
while (start != first) {
r = tryMatch(start, end, &child, level, matches, ids);
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()};
break;
}
@ -255,8 +255,8 @@ const SegementNode *UrlRouterPrivate::tryMatch(boost::urls::segments_encoded_bas
const SegementNode *UrlRouterPrivate::findOptionalResource(const SegementNode *root,
const std::vector<SegementNode> &ns,
boost::urls::string_view *&matches,
boost::urls::string_view *&ids) {
boost::core::string_view *&matches,
boost::core::string_view *&ids) {
BOOST_ASSERT(root);
if (root->resource) return root;
BOOST_ASSERT(!root->childIndexes.empty());

View File

@ -45,16 +45,16 @@ public:
class UrlRouterPrivate {
public:
UrlRouterPrivate();
void insertImpl(boost::urls::string_view pattern, const std::shared_ptr<AnyResource> &resource);
const AnyResource *findImpl(boost::urls::segments_encoded_view path, boost::urls::string_view *&matches,
boost::urls::string_view *&ids) const noexcept;
void insertImpl(boost::core::string_view pattern, const std::shared_ptr<AnyResource> &resource);
const AnyResource *findImpl(boost::urls::segments_encoded_view path, boost::core::string_view *&matches,
boost::core::string_view *&ids) const noexcept;
protected:
SegementNode const *tryMatch(boost::urls::segments_encoded_view::const_iterator it,
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,
boost::urls::string_view *&matches, boost::urls::string_view *&ids);
boost::core::string_view *&matches, boost::core::string_view *&ids);
private:
std::vector<SegementNode> m_nodes;