diff --git a/console/atest-desktop/forge.config.js b/console/atest-desktop/forge.config.js index 01f215bff..cd3c74359 100644 --- a/console/atest-desktop/forge.config.js +++ b/console/atest-desktop/forge.config.js @@ -51,6 +51,26 @@ module.exports = { ui: { "enabled": true, "chooseDirectory": true + }, + beforeCreate: (msiCreator) => { + // Add installation directory to system PATH + msiCreator.wixTemplate = msiCreator.wixTemplate.replace( + '', + ` + + + + + NOT Installed + REMOVE="ALL" + + + + + + + ` + ); } } } diff --git a/docs/site/content/zh/latest/tasks/mock.md b/docs/site/content/zh/latest/tasks/mock.md index cec85f0bf..adff4c18a 100644 --- a/docs/site/content/zh/latest/tasks/mock.md +++ b/docs/site/content/zh/latest/tasks/mock.md @@ -234,8 +234,11 @@ items: proxies: - path: /api/v1/{part} target: http://atest.localhost:8080 + echo: true ``` +当 echo 的值为 true 时,会把收到的请求以及响应打印出来,方便观察数据。 + 当我们发起如下的请求时,实际请求的地址为 `http://atest.localhost:8080/api/v1/projects` ```shell @@ -293,4 +296,16 @@ proxies: * HTTP * Syslog +```yaml +webhooks: + - timer: 3s + name: shakeHands + request: + method: POST + path: http://192.168.1.123:8080/api/v1 + header: + Content-Type: application/json + bodyFromFile: demo.json +``` + > 更多 URL 中通配符的用法,请参考 https://github.com/gorilla/mux diff --git a/docs/site/content/zh/latest/tasks/mock/simple.yaml b/docs/site/content/zh/latest/tasks/mock/simple.yaml index 2d756f675..298c2c228 100644 --- a/docs/site/content/zh/latest/tasks/mock/simple.yaml +++ b/docs/site/content/zh/latest/tasks/mock/simple.yaml @@ -39,6 +39,7 @@ proxies: target: http://atest.localhost:8080 - path: /open-apis/bot/v2/hook/{token} target: https://open.feishu.cn/ + echo: true requestAmend: bodyPatch: | [{ diff --git a/pkg/mock/in_memory.go b/pkg/mock/in_memory.go index 4a59013a4..c7767b821 100644 --- a/pkg/mock/in_memory.go +++ b/pkg/mock/in_memory.go @@ -178,6 +178,16 @@ func (s *inMemoryServer) httpProxy(proxy *Proxy) { fmt.Println("after patch:", string(requestBody)) } + if proxy.Echo { + fmt.Println("Original request header:") + for k, v := range req.Header { + fmt.Println(k, ":", v) + } + fmt.Println("Original request path:", req.URL) + fmt.Println("Original request payload:") + fmt.Println(string(requestBody)) + } + targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody)) if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -206,6 +216,12 @@ func (s *inMemoryServer) httpProxy(proxy *Proxy) { for k, v := range resp.Header { w.Header().Add(k, v[0]) } + + if proxy.Echo { + fmt.Println("Original response payload:") + fmt.Println(string(data)) + } + w.Write(data) }) } @@ -580,6 +596,15 @@ func runWebhook(ctx context.Context, objCtx interface{}, wh *Webhook) (err error } } + if wh.Request.BodyFromFile != "" { + if data, readErr := os.ReadFile(wh.Request.BodyFromFile); readErr != nil { + memLogger.Error(readErr, "failed to read file", "file", wh.Request.BodyFromFile) + return + } else { + wh.Request.Body = string(data) + } + } + var payload io.Reader payload, err = render.RenderAsReader("mock webhook server payload", wh.Request.Body, wh) if err != nil { diff --git a/pkg/mock/types.go b/pkg/mock/types.go index b37911757..ba64796e3 100644 --- a/pkg/mock/types.go +++ b/pkg/mock/types.go @@ -29,11 +29,12 @@ type Item struct { } type Request struct { - Protocol string `yaml:"protocol" json:"protocol"` - Path string `yaml:"path" json:"path"` - Method string `yaml:"method" json:"method"` - Header map[string]string `yaml:"header" json:"header"` - Body string `yaml:"body" json:"body"` + Protocol string `yaml:"protocol" json:"protocol"` + Path string `yaml:"path" json:"path"` + Method string `yaml:"method" json:"method"` + Header map[string]string `yaml:"header" json:"header"` + Body string `yaml:"body" json:"body"` + BodyFromFile string `yaml:"bodyFromFile" json:"bodyFromFile"` } type RequestWithAuth struct { @@ -66,6 +67,7 @@ type Proxy struct { Target string `yaml:"target" json:"target"` RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"` Protocol string `yaml:"protocol" json:"protocol"` + Echo bool `yaml:"echo" json:"echo"` } type RequestAmend struct {