Software /
code /
prosody-modules
Comparison
mod_http_debug/mod_http_debug.lua @ 5490:91564b57e595
mod_http_debug: Handle more HTTP methods
Often you might want to see what POST data was sent, or such.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 26 May 2023 15:36:04 +0200 |
parent | 5333:10fcfa7e62a1 |
child | 5491:7842502c1157 |
comparison
equal
deleted
inserted
replaced
5489:a7188eb4ded4 | 5490:91564b57e595 |
---|---|
1 local json = require "util.json" | 1 local json = require "util.json" |
2 | 2 |
3 module:depends("http") | 3 module:depends("http") |
4 local function handle_request(event) | |
5 local request = event.request; | |
6 return { | |
7 status_code = 200; | |
8 headers = { content_type = "application/json" }; | |
9 host = module.host; | |
10 body = json.encode { | |
11 body = request.body; | |
12 headers = request.headers; | |
13 httpversion = request.httpversion; | |
14 id = request.id; | |
15 ip = request.ip; | |
16 method = request.method; | |
17 path = request.path; | |
18 secure = request.secure; | |
19 url = request.url; | |
20 }; | |
21 } | |
22 end | |
23 | |
24 local methods = module:get_option_set("http_debug_methods", { "GET"; "HEAD"; "DELETE"; "OPTIONS"; "PATCH"; "POST"; "PUT" }); | |
25 local route = {}; | |
26 for method in methods do | |
27 route[method] = handle_request; | |
28 end | |
29 | |
4 module:provides("http", { | 30 module:provides("http", { |
5 route = { | 31 route = route; |
6 GET = function(event) | 32 }) |
7 local request = event.request; | |
8 return { | |
9 status_code = 200; | |
10 headers = { | |
11 content_type = "application/json", | |
12 }, | |
13 body = json.encode { | |
14 body = request.body; | |
15 headers = request.headers; | |
16 httpversion = request.httpversion; | |
17 ip = request.ip; | |
18 method = request.method; | |
19 path = request.path; | |
20 secure = request.secure; | |
21 url = request.url; | |
22 } | |
23 } | |
24 end; | |
25 } | |
26 }) |