0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::resource: Add MIME type requirement option for methods.

This commit is contained in:
Jason Volk 2018-05-09 17:44:12 -07:00
parent cb2c95ceb6
commit 6feaa95d4b
2 changed files with 19 additions and 0 deletions

View file

@ -194,6 +194,9 @@ struct ircd::resource::method
/// larger will be summarily rejected with a 413.
size_t payload_max {128_KiB};
/// MIME type; first part is the Registry (i.e application) and second
/// part is the format (i.e json). Empty value means nothing rejected.
std::pair<string_view, string_view> mime;
};
string_view name;

View file

@ -278,6 +278,22 @@ ircd::resource::operator()(client &client,
http::PAYLOAD_TOO_LARGE
};
// Check if the resource method wants a specific MIME type. If no option
// is given by the resource then any Content-Type by the client will pass.
if(method.opts.mime.first)
{
const auto &ct(split(head.content_type, ';'));
const auto &supplied(split(ct.first, '/'));
const auto &charset(ct.second);
const auto &required(method.opts.mime);
if(required.first != supplied.first ||
(required.second && required.second != supplied.second))
throw http::error
{
http::UNSUPPORTED_MEDIA_TYPE
};
}
// This timer will keep the request from hanging forever for whatever
// reason. The resource method may want to do its own timing and can
// disable this in its options structure.