Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
4035:270cd50852be | 4036:04c11b652aeb |
---|---|
124 to = { code = 422, condition = "improper-addressing", text = "Invalid destination JID", }, | 124 to = { code = 422, condition = "improper-addressing", text = "Invalid destination JID", }, |
125 from = { code = 422, condition = "invalid-from", text = "Invalid source JID", }, | 125 from = { code = 422, condition = "invalid-from", text = "Invalid source JID", }, |
126 post_auth = { code = 403, condition = "not-authorized", text = "Not authorized to send stanza with requested 'from'", }, | 126 post_auth = { code = 403, condition = "not-authorized", text = "Not authorized to send stanza with requested 'from'", }, |
127 iq_type = { code = 422, condition = "invalid-xml", text = "'iq' stanza must be of type 'get' or 'set'", }, | 127 iq_type = { code = 422, condition = "invalid-xml", text = "'iq' stanza must be of type 'get' or 'set'", }, |
128 iq_tags = { code = 422, condition = "bad-format", text = "'iq' stanza must have exactly one child tag", }, | 128 iq_tags = { code = 422, condition = "bad-format", text = "'iq' stanza must have exactly one child tag", }, |
129 mediatype = { code = 415, condition = "bad-format", text = "Unsupported media type" }, | |
129 }; | 130 }; |
130 | 131 |
131 local function handle_post(event) | 132 local function handle_post(event) |
132 local request, response = event.request, event.response; | 133 local request, response = event.request, event.response; |
133 local from; | 134 local from; |
144 from = jid.join(origin.username, origin.host, origin.resource); | 145 from = jid.join(origin.username, origin.host, origin.resource); |
145 end | 146 end |
146 local payload, err = parse(request.headers.content_type, request.body); | 147 local payload, err = parse(request.headers.content_type, request.body); |
147 if not payload then | 148 if not payload then |
148 -- parse fail | 149 -- parse fail |
149 return errors.new("parse", { error = err, type = request.headers.content_type, data = request.body, }, post_errors); | 150 local ctx = { error = err, type = request.headers.content_type, data = request.body, }; |
151 if err == "unknown-payload-type" then | |
152 return errors.new("mediatype", ctx, post_errors); | |
153 end | |
154 return errors.new("parse", ctx, post_errors); | |
150 end | 155 end |
151 if payload.attr.xmlns then | 156 if payload.attr.xmlns then |
152 return errors.new("xmlns", nil, post_errors); | 157 return errors.new("xmlns", nil, post_errors); |
153 elseif payload.name ~= "message" and payload.name ~= "presence" and payload.name ~= "iq" then | 158 elseif payload.name ~= "message" and payload.name ~= "presence" and payload.name ~= "iq" then |
154 return errors.new("name", nil, post_errors); | 159 return errors.new("name", nil, post_errors); |