comparison mod_http_rest/mod_http_rest.lua @ 2336:79432b859d21

New module: mod_http_rest.lua
author JC Brand <jcbrand@minddistrict.com>
date Mon, 17 Oct 2016 12:56:05 +0000
parents
children
comparison
equal deleted inserted replaced
2335:eb456fd639d2 2336:79432b859d21
1 module:depends"http"
2
3 local jid_split = require "util.jid".split;
4 local jid_prep = require "util.jid".prep;
5 local stanza = require "util.stanza";
6 local test_password = require "core.usermanager".test_password;
7 local b64_decode = require "util.encodings".base64.decode;
8 local formdecode = require "net.http".formdecode;
9 local xml = require"util.xml";
10
11 local function handle_post(event, path, authed_user)
12 local request = event.request;
13 local headers = request.headers;
14 local body_type = headers.content_type;
15 if body_type == "text/xml" and request.body then
16 local parsed, err = xml.parse(request.body);
17 if parsed then
18 module:log("debug", "Sending %s", parsed);
19 module:send(parsed);
20 return 201;
21 end
22 else
23 return 415;
24 end
25 return 422;
26 end
27
28 module:provides("http", {
29 default_path = "/rest";
30 route = {
31 ["POST"] = handle_post;
32 OPTIONS = function(e)
33 local headers = e.response.headers;
34 headers.allow = "POST";
35 headers.accept = "test/xml";
36 return 200;
37 end;
38 }
39 });