mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd: Split out allow methods list generator.
This commit is contained in:
parent
a2be4d3ee5
commit
ba6832b420
2 changed files with 22 additions and 12 deletions
|
@ -35,6 +35,8 @@ struct ircd::resource
|
|||
std::map<string_view, method *> methods;
|
||||
unique_const_iterator<decltype(resources)> resources_it;
|
||||
|
||||
string_view allow_methods_list(const mutable_buffer &buf);
|
||||
|
||||
private:
|
||||
virtual void handle_request(client &, method &, resource::request &);
|
||||
|
||||
|
|
|
@ -312,10 +312,7 @@ ircd::resource::handle_request(client &client,
|
|||
resource::request &request)
|
||||
try
|
||||
{
|
||||
const auto response
|
||||
{
|
||||
method(client, request)
|
||||
};
|
||||
method(client, request);
|
||||
}
|
||||
catch(const json::not_found &e)
|
||||
{
|
||||
|
@ -360,9 +357,26 @@ try
|
|||
return *methods.at(name);
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
char buf[128];
|
||||
const http::header headers[]
|
||||
{
|
||||
{ "Allow", allow_methods_list(buf) }
|
||||
};
|
||||
|
||||
throw http::error
|
||||
{
|
||||
http::METHOD_NOT_ALLOWED, {}, headers
|
||||
};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::resource::allow_methods_list(const mutable_buffer &buf)
|
||||
{
|
||||
size_t len(0);
|
||||
char buf[128]; buf[0] = '\0';
|
||||
if(likely(size(buf)))
|
||||
buf[len] = '\0';
|
||||
|
||||
auto it(begin(methods));
|
||||
if(it != end(methods))
|
||||
{
|
||||
|
@ -374,13 +388,7 @@ catch(const std::out_of_range &e)
|
|||
}
|
||||
}
|
||||
|
||||
throw http::error
|
||||
{
|
||||
http::METHOD_NOT_ALLOWED, {},
|
||||
{
|
||||
{ "Allow", string_view{buf, len} }
|
||||
}
|
||||
};
|
||||
return { data(buf), len };
|
||||
}
|
||||
|
||||
ircd::resource::method::method(struct resource &resource,
|
||||
|
|
Loading…
Reference in a new issue