mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::resource: Simplify the resource entry interface.
This commit is contained in:
parent
fdff7428ce
commit
8b9b27d8bc
3 changed files with 15 additions and 23 deletions
|
@ -38,10 +38,9 @@ struct ircd::resource
|
||||||
unique_const_iterator<decltype(resources)> resources_it;
|
unique_const_iterator<decltype(resources)> resources_it;
|
||||||
|
|
||||||
string_view allow_methods_list(const mutable_buffer &buf) const;
|
string_view allow_methods_list(const mutable_buffer &buf) const;
|
||||||
method &operator[](const string_view &path) const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void operator()(client &, const http::request::head &, const string_view &content_partial);
|
method &operator[](const string_view &name) const;
|
||||||
|
|
||||||
resource(const string_view &path, struct opts);
|
resource(const string_view &path, struct opts);
|
||||||
resource(const string_view &path);
|
resource(const string_view &path);
|
||||||
|
|
|
@ -800,17 +800,24 @@ bool
|
||||||
ircd::client::resource_request(const http::request::head &head)
|
ircd::client::resource_request(const http::request::head &head)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
auto &resource
|
||||||
|
{
|
||||||
|
// throws HTTP 404 if not found.
|
||||||
|
ircd::resource::find(head.path)
|
||||||
|
};
|
||||||
|
|
||||||
|
auto &method
|
||||||
|
{
|
||||||
|
// throws HTTP 405 if not found.
|
||||||
|
resource[head.method]
|
||||||
|
};
|
||||||
|
|
||||||
const string_view content_partial
|
const string_view content_partial
|
||||||
{
|
{
|
||||||
data(head_buffer) + head_length, content_consumed
|
data(head_buffer) + head_length, content_consumed
|
||||||
};
|
};
|
||||||
|
|
||||||
auto &resource
|
method(*this, head, content_partial);
|
||||||
{
|
|
||||||
ircd::resource::find(head.path)
|
|
||||||
};
|
|
||||||
|
|
||||||
resource(*this, head, content_partial);
|
|
||||||
discard_unconsumed(head);
|
discard_unconsumed(head);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,20 +156,6 @@ noexcept
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ircd::resource::operator()(client &client,
|
|
||||||
const http::request::head &head,
|
|
||||||
const string_view &content_partial)
|
|
||||||
{
|
|
||||||
// Find the method or METHOD_NOT_ALLOWED
|
|
||||||
auto &method
|
|
||||||
{
|
|
||||||
operator[](head.method)
|
|
||||||
};
|
|
||||||
|
|
||||||
method(client, head, content_partial);
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::resource::method &
|
ircd::resource::method &
|
||||||
ircd::resource::operator[](const string_view &name)
|
ircd::resource::operator[](const string_view &name)
|
||||||
const try
|
const try
|
||||||
|
@ -178,7 +164,7 @@ const try
|
||||||
}
|
}
|
||||||
catch(const std::out_of_range &e)
|
catch(const std::out_of_range &e)
|
||||||
{
|
{
|
||||||
char buf[128];
|
thread_local char buf[512];
|
||||||
const http::header headers[]
|
const http::header headers[]
|
||||||
{
|
{
|
||||||
{ "Allow", allow_methods_list(buf) }
|
{ "Allow", allow_methods_list(buf) }
|
||||||
|
|
Loading…
Reference in a new issue