From f0c54be43f26993d024a98a401a03dc6badc05e0 Mon Sep 17 00:00:00 2001 From: Anders Kvist Date: Sat, 9 Sep 2023 12:05:25 +0200 Subject: [PATCH] Adding x-www-form-urlencoded (#3499) * Adding x-www-form-urlencoded * Adding example of x-www-form-urlencoding to body. * A bit cleaner. * Update server/model/monitor.js Co-authored-by: Frank Elsinga * Update src/pages/EditMonitor.vue Co-authored-by: Frank Elsinga * Update src/pages/EditMonitor.vue Co-authored-by: Matthew Nickson * Add simple test --------- Co-authored-by: Anders Kvist Co-authored-by: Frank Elsinga Co-authored-by: Louis Lam Co-authored-by: Matthew Nickson --- server/model/monitor.js | 3 +++ server/server.js | 6 ++++++ src/pages/EditMonitor.vue | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/server/model/monitor.js b/server/model/monitor.js index 09d0f2b5..85d98d18 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -431,6 +431,9 @@ class Monitor extends BeanModel { } catch (e) { throw new Error("Your JSON body is invalid. " + e.message); } + } else if (this.httpBodyEncoding === "form") { + bodyValue = this.body; + contentType = "application/x-www-form-urlencoded"; } else if (this.httpBodyEncoding === "xml") { bodyValue = this.body; contentType = "text/xml; charset=utf-8"; diff --git a/server/server.js b/server/server.js index 2cf616a9..5bded809 100644 --- a/server/server.js +++ b/server/server.js @@ -251,6 +251,12 @@ let needSetup = false; log.debug("test", request.body); response.send("OK"); }); + + app.post("/test-x-www-form-urlencoded", async (request, response) => { + log.debug("test", request.headers); + log.debug("test", request.body); + response.send("OK"); + }); } // Robots.txt diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index c8b16663..f59a2d57 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -654,6 +654,7 @@ @@ -1002,6 +1003,9 @@ message HealthCheckResponse { ` ]); } + if (this.monitor && this.monitor.httpBodyEncoding === "form") { + return this.$t("Example:", [ "key1=value1&key2=value2" ]); + } return this.$t("Example:", [ ` { "key": "value"