diff --git a/include/ircd/resource/resource.h b/include/ircd/resource/resource.h index 4879810e1..d109c9a7b 100644 --- a/include/ircd/resource/resource.h +++ b/include/ircd/resource/resource.h @@ -37,8 +37,12 @@ struct ircd::resource std::unique_ptr opts; std::map methods; unique_const_iterator resources_it; + std::unique_ptr default_method_head; + std::unique_ptr 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 diff --git a/ircd/resource.cc b/ircd/resource.cc index 1c23ddfb1..891623c4b 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -139,6 +139,32 @@ ircd::resource::resource(const string_view &path, resources, iit.first }; }()} +,default_method_head{[this, &opts] +() -> std::unique_ptr +{ + if(opts.flags & flag::OVERRIDE_HEAD) + return {}; + + auto handler + { + std::bind(&resource::handle_head, this, ph::_1, ph::_2) + }; + + return std::make_unique(*this, "HEAD", std::move(handler)); +}()} +,default_method_options{[this, &opts] +() -> std::unique_ptr +{ + if(opts.flags & flag::OVERRIDE_OPTIONS) + return {}; + + auto handler + { + std::bind(&resource::handle_options, this, ph::_1, ph::_2) + }; + + return std::make_unique(*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