mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::resource: Stub default/builtin method handlers for OPTIONS and HEAD.
This commit is contained in:
parent
ae936d8e55
commit
af08458f8d
2 changed files with 55 additions and 1 deletions
|
@ -37,8 +37,12 @@ struct ircd::resource
|
|||
std::unique_ptr<const struct opts> opts;
|
||||
std::map<string_view, method *> methods;
|
||||
unique_const_iterator<decltype(resources)> resources_it;
|
||||
std::unique_ptr<method> default_method_head;
|
||||
std::unique_ptr<method> default_method_options;
|
||||
|
||||
string_view allow_methods_list(const mutable_buffer &buf) const;
|
||||
response handle_options(client &, const request &) const;
|
||||
response handle_head(client &, const request &) const;
|
||||
|
||||
public:
|
||||
method &operator[](const string_view &name) const;
|
||||
|
@ -59,7 +63,9 @@ struct ircd::resource
|
|||
enum ircd::resource::flag
|
||||
:uint
|
||||
{
|
||||
DIRECTORY = 0x01,
|
||||
DIRECTORY = 0x01,
|
||||
OVERRIDE_HEAD = 0x02,
|
||||
OVERRIDE_OPTIONS = 0x04,
|
||||
};
|
||||
|
||||
struct ircd::resource::opts
|
||||
|
|
|
@ -139,6 +139,32 @@ ircd::resource::resource(const string_view &path,
|
|||
resources, iit.first
|
||||
};
|
||||
}()}
|
||||
,default_method_head{[this, &opts]
|
||||
() -> std::unique_ptr<method>
|
||||
{
|
||||
if(opts.flags & flag::OVERRIDE_HEAD)
|
||||
return {};
|
||||
|
||||
auto handler
|
||||
{
|
||||
std::bind(&resource::handle_head, this, ph::_1, ph::_2)
|
||||
};
|
||||
|
||||
return std::make_unique<method>(*this, "HEAD", std::move(handler));
|
||||
}()}
|
||||
,default_method_options{[this, &opts]
|
||||
() -> std::unique_ptr<method>
|
||||
{
|
||||
if(opts.flags & flag::OVERRIDE_OPTIONS)
|
||||
return {};
|
||||
|
||||
auto handler
|
||||
{
|
||||
std::bind(&resource::handle_options, this, ph::_1, ph::_2)
|
||||
};
|
||||
|
||||
return std::make_unique<method>(*this, "OPTIONS", std::move(handler));
|
||||
}()}
|
||||
{
|
||||
log::debug
|
||||
{
|
||||
|
@ -181,6 +207,28 @@ catch(const std::out_of_range &e)
|
|||
};
|
||||
}
|
||||
|
||||
ircd::resource::response
|
||||
ircd::resource::handle_head(client &client,
|
||||
const request &request)
|
||||
const
|
||||
{
|
||||
return response
|
||||
{
|
||||
client, http::METHOD_NOT_ALLOWED
|
||||
};
|
||||
}
|
||||
|
||||
ircd::resource::response
|
||||
ircd::resource::handle_options(client &client,
|
||||
const request &request)
|
||||
const
|
||||
{
|
||||
return response
|
||||
{
|
||||
client, http::METHOD_NOT_ALLOWED
|
||||
};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::resource::allow_methods_list(const mutable_buffer &buf)
|
||||
const
|
||||
|
|
Loading…
Reference in a new issue