Merge pull request #2610 from bayramberkay/feature/add-xml-support-to-http-monitors

Add xml support to HTTP monitors
This commit is contained in:
Louis Lam
2023-02-24 17:26:47 +08:00
committed by GitHub
6 changed files with 58 additions and 6 deletions

View File

@@ -671,5 +671,6 @@
"Google Analytics ID": "Google Analytics ID",
"Edit Tag": "Edit Tag",
"Server Address": "Server Address",
"Learn More": "Learn More"
"Learn More": "Learn More",
"Body Encoding": "Body Encoding"
}

View File

@@ -503,6 +503,15 @@
</select>
</div>
<!-- Encoding -->
<div class="my-3">
<label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label>
<select id="httpBodyEncoding" v-model="monitor.httpBodyEncoding" class="form-select">
<option value="json">JSON</option>
<option value="xml">XML</option>
</select>
</div>
<!-- Body -->
<div class="my-3">
<label for="body" class="form-label">{{ $t("Body") }}</label>
@@ -723,6 +732,15 @@ message HealthCheckResponse {
` ]);
},
bodyPlaceholder() {
if (this.monitor && this.monitor.httpBodyEncoding && this.monitor.httpBodyEncoding === "xml") {
return this.$t("Example:", [ `
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Uptime>Kuma</Uptime>
</soap:Body>
</soap:Envelope>` ]);
}
return this.$t("Example:", [ `
{
"key": "value"
@@ -872,6 +890,7 @@ message HealthCheckResponse {
mqttTopic: "",
mqttSuccessMessage: "",
authMethod: null,
httpBodyEncoding: "json"
};
if (this.$root.proxyList && !this.monitor.proxyId) {
@@ -909,7 +928,7 @@ message HealthCheckResponse {
* @returns {boolean} Is the form input valid?
*/
isInputValid() {
if (this.monitor.body) {
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
try {
JSON.parse(this.monitor.body);
} catch (err) {
@@ -933,6 +952,7 @@ message HealthCheckResponse {
* @returns {void}
*/
async submit() {
this.processing = true;
if (!this.isInputValid()) {
@@ -940,11 +960,15 @@ message HealthCheckResponse {
return;
}
// Beautify the JSON format
if (this.monitor.body) {
// Beautify the JSON format (only if httpBodyEncoding is not set or === json)
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4);
}
if (this.monitor.type && this.monitor.type !== "http" && this.monitor.type !== "keyword") {
this.monitor.httpBodyEncoding = null;
}
if (this.monitor.headers) {
this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4);
}