# HG changeset patch # User Kim Alvefur # Date 1590748215 -7200 # Node ID 04c11b652aeb052fbdefcd96a15680b52790d4b6 # Parent 270cd50852be095e9db46ec1043e095d19d0874e mod_rest: Respond to unknown payload types with HTTP status 415 More semantically correct. diff -r 270cd50852be -r 04c11b652aeb mod_rest/mod_rest.lua --- 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);