Software /
code /
prosody
Comparison
plugins/mod_xmlrpc.lua @ 880:ff4a08d73772
XML-RPC: Set appropriate Content-Type header in HTTP response
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 04 Mar 2009 22:59:58 +0500 |
parent | 877:0bababc930dd |
child | 889:bb959588bbc4 |
comparison
equal
deleted
inserted
replaced
879:2189baddedb8 | 880:ff4a08d73772 |
---|---|
100 end | 100 end |
101 end | 101 end |
102 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:rpc", handle_xmpp_request); | 102 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:rpc", handle_xmpp_request); |
103 module:add_feature("jabber:iq:rpc"); | 103 module:add_feature("jabber:iq:rpc"); |
104 | 104 |
105 local default_headers = { ["Content-Type"] = "text/xml" }; | |
105 local function handle_http_request(method, body, request) | 106 local function handle_http_request(method, body, request) |
106 local stanza = body and parse_xml(body); | 107 local stanza = body and parse_xml(body); |
107 if (not stanza) or request.method ~= "POST" then | 108 if (not stanza) or request.method ~= "POST" then |
108 return "<html><body>You really don't look like an XML-RPC client to me... what do you want?</body></html>"; | 109 return "<html><body>You really don't look like an XML-RPC client to me... what do you want?</body></html>"; |
109 end | 110 end |
110 local success, method, args = pcall(translate_request, stanza); | 111 local success, method, args = pcall(translate_request, stanza); |
111 if success then | 112 if success then |
112 return tostring(handle_xmlrpc_request(method, args)); | 113 return { headers = default_headers; body = tostring(handle_xmlrpc_request(method, args)) }; |
113 end | 114 end |
114 return "<html><body>You really don't look like an XML-RPC client to me... what do you want?</body></html>"; | 115 return "<html><body>Error parsing XML-RPC request: "..tostring(method).."</body></html>"; |
115 end | 116 end |
116 httpserver.new{ port = 9000, base = "xmlrpc", handler = handle_http_request } | 117 httpserver.new{ port = 9000, base = "xmlrpc", handler = handle_http_request } |