Software /
code /
prosody-modules
Diff
mod_rest/mod_rest.lua @ 4036:04c11b652aeb
mod_rest: Respond to unknown payload types with HTTP status 415
More semantically correct.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 29 May 2020 12:30:15 +0200 |
parent | 3971:ae5ac41c391d |
child | 4037:991090cb5d18 |
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua Fri May 29 12:04:04 2020 +0200 +++ b/mod_rest/mod_rest.lua Fri May 29 12:30:15 2020 +0200 @@ -126,6 +126,7 @@ post_auth = { code = 403, condition = "not-authorized", text = "Not authorized to send stanza with requested 'from'", }, iq_type = { code = 422, condition = "invalid-xml", text = "'iq' stanza must be of type 'get' or 'set'", }, iq_tags = { code = 422, condition = "bad-format", text = "'iq' stanza must have exactly one child tag", }, + mediatype = { code = 415, condition = "bad-format", text = "Unsupported media type" }, }; local function handle_post(event) @@ -146,7 +147,11 @@ local payload, err = parse(request.headers.content_type, request.body); if not payload then -- parse fail - return errors.new("parse", { error = err, type = request.headers.content_type, data = request.body, }, post_errors); + local ctx = { error = err, type = request.headers.content_type, data = request.body, }; + if err == "unknown-payload-type" then + return errors.new("mediatype", ctx, post_errors); + end + return errors.new("parse", ctx, post_errors); end if payload.attr.xmlns then return errors.new("xmlns", nil, post_errors);