Mercurial > prosody-modules
comparison mod_rest/mod_rest.lua @ 3861:ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 25 Jan 2020 20:04:39 +0100 |
| parents | 29c39876c4af |
| children | 3b6b8dcff78e |
comparison
equal
deleted
inserted
replaced
| 3860:9752a6f1b9f3 | 3861:ede3d1724dd1 |
|---|---|
| 150 if rest_url then | 150 if rest_url then |
| 151 local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml"); | 151 local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml"); |
| 152 if send_type == "json" then | 152 if send_type == "json" then |
| 153 send_type = "application/json"; | 153 send_type = "application/json"; |
| 154 end | 154 end |
| 155 | |
| 156 http.request(rest_url, { | |
| 157 method = "OPTIONS", | |
| 158 }, function (body, code, response) | |
| 159 if code == 200 and response.headers.accept then | |
| 160 send_type = decide_type(response.headers.accept); | |
| 161 module:log("debug", "Set 'rest_callback_content_type' = %q based on Accept header", send_type); | |
| 162 end | |
| 163 end); | |
| 155 | 164 |
| 156 local code2err = { | 165 local code2err = { |
| 157 [400] = { condition = "bad-request"; type = "modify" }; | 166 [400] = { condition = "bad-request"; type = "modify" }; |
| 158 [401] = { condition = "not-authorized"; type = "auth" }; | 167 [401] = { condition = "not-authorized"; type = "auth" }; |
| 159 [402] = { condition = "not-authorized"; type = "auth" }; | 168 [402] = { condition = "not-authorized"; type = "auth" }; |
