From b72d91d0d4041707ff1cc5cf36cfab3d103b7568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Tue, 7 Dec 2021 15:03:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=97=A5=E5=BF=97=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=AE=B0=E5=BD=95=E5=92=8C=E6=98=BE=E7=A4=BArequestBo?= =?UTF-8?q?dy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/servers/server/log/viewPopup.go | 15 +++++ .../js/components/common/source-code-box.js | 61 ++++++++++++------- .../server/http-access-log-config-box.js | 19 ++++-- .../servers/server/log/viewPopup.html | 6 ++ 4 files changed, 75 insertions(+), 26 deletions(-) diff --git a/internal/web/actions/default/servers/server/log/viewPopup.go b/internal/web/actions/default/servers/server/log/viewPopup.go index b23b7c9a..397eb628 100644 --- a/internal/web/actions/default/servers/server/log/viewPopup.go +++ b/internal/web/actions/default/servers/server/log/viewPopup.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" "net/http" + "strings" ) type ViewPopupAction struct { @@ -98,5 +99,19 @@ func (this *ViewPopupAction) RunGet(params struct { } this.Data["region"] = regionMap + // 请求内容 + this.Data["requestBody"] = string(accessLog.RequestBody) + this.Data["requestContentType"] = "text/plain" + + requestContentType, ok := accessLog.Header["Content-Type"] + if ok { + if len(requestContentType.Values) > 0 { + var contentType = requestContentType.Values[0] + if strings.HasSuffix(contentType, "/json") || strings.Contains(contentType, "/json;") { + this.Data["requestContentType"] = "application/json" + } + } + } + this.Show() } diff --git a/web/public/js/components/common/source-code-box.js b/web/public/js/components/common/source-code-box.js index 6ffc1e01..b83af969 100644 --- a/web/public/js/components/common/source-code-box.js +++ b/web/public/js/components/common/source-code-box.js @@ -1,7 +1,7 @@ let sourceCodeBoxIndex = 0 Vue.component("source-code-box", { - props: ["name", "type", "id", "read-only"], + props: ["name", "type", "id", "read-only", "width", "height"], mounted: function () { let readOnly = this.readOnly if (typeof readOnly != "boolean") { @@ -15,27 +15,46 @@ Vue.component("source-code-box", { } else if (valueBox.innerText != null) { value = valueBox.innerText } - let boxEditor = CodeMirror.fromTextArea(box, { - theme: "idea", - lineNumbers: true, - value: "", - readOnly: readOnly, - showCursorWhenSelecting: true, - height: "auto", - //scrollbarStyle: null, - viewportMargin: Infinity, - lineWrapping: true, - highlightFormatting: false, - indentUnit: 4, - indentWithTabs: true - }) - boxEditor.setValue(value) - let info = CodeMirror.findModeByMIME(this.type) - if (info != null) { - boxEditor.setOption("mode", info.mode) - CodeMirror.modeURL = "/codemirror/mode/%N/%N.js" - CodeMirror.autoLoadMode(boxEditor, info.mode) + this.createEditor(box, value, readOnly) + }, + methods: { + createEditor: function (box, value, readOnly) { + let boxEditor = CodeMirror.fromTextArea(box, { + theme: "idea", + lineNumbers: true, + value: "", + readOnly: readOnly, + showCursorWhenSelecting: true, + height: "auto", + //scrollbarStyle: null, + viewportMargin: Infinity, + lineWrapping: true, + highlightFormatting: false, + indentUnit: 4, + indentWithTabs: true + }) + boxEditor.setValue(value) + + let width = this.width + let height = this.height + if (width != null && height != null) { + width = parseInt(width) + height = parseInt(height) + if (!isNaN(width) && !isNaN(height)) { + if (width <= 0) { + width = box.parentNode.offsetWidth + } + boxEditor.setSize(width, height) + } + } + + let info = CodeMirror.findModeByMIME(this.type) + if (info != null) { + boxEditor.setOption("mode", info.mode) + CodeMirror.modeURL = "/codemirror/mode/%N/%N.js" + CodeMirror.autoLoadMode(boxEditor, info.mode) + } } }, data: function () { diff --git a/web/public/js/components/server/http-access-log-config-box.js b/web/public/js/components/server/http-access-log-config-box.js index 9b350116..3cbf352e 100644 --- a/web/public/js/components/server/http-access-log-config-box.js +++ b/web/public/js/components/server/http-access-log-config-box.js @@ -34,7 +34,8 @@ Vue.component("http-access-log-config-box", { }) return { - accessLog: accessLog + accessLog: accessLog, + hasRequestBodyField: this.vFields.$contains(8) } }, methods: { @@ -44,6 +45,7 @@ Vue.component("http-access-log-config-box", { }).map(function (v) { return v.code }) + this.hasRequestBodyField = this.accessLog.fields.$contains(8) } }, template: `
@@ -64,12 +66,19 @@ Vue.component("http-access-log-config-box", { - 要存储的访问日志字段 + 基础信息 +

默认记录客户端IP、请求URL等基础信息。

+ + + 高级信息 -
- - +
+ +
+

在基础信息之外要存储的信息。 + 记录"请求Body"将会显著消耗更多的系统资源,建议仅在调试时启用,最大记录尺寸为2MB。 +

diff --git a/web/views/@default/servers/server/log/viewPopup.html b/web/views/@default/servers/server/log/viewPopup.html index 5092e505..3a554022 100644 --- a/web/views/@default/servers/server/log/viewPopup.html +++ b/web/views/@default/servers/server/log/viewPopup.html @@ -1,4 +1,5 @@ {$layout "layout_popup"} +{$template "/code_editor"}