diff options
author | techknowlogick <matti@mdranta.net> | 2019-05-15 08:01:53 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-05-15 20:01:53 +0800 |
commit | 5fb1ad70113d3272232c266b4ff58e9f7f646594 (patch) | |
tree | 6264cc7cba7fbff0d12b638764d4f77d07db6707 /models/webhook.go | |
parent | 710245e81e0d65c72231dbb3b5c9f860cdc71899 (diff) | |
download | gitea-5fb1ad70113d3272232c266b4ff58e9f7f646594.tar.gz gitea-5fb1ad70113d3272232c266b4ff58e9f7f646594.zip |
Webhook Logs show proper HTTP Method, and allow change HTTP method in form (#6953)
* Fix #6951 - logs show proper HTTP Method, and allow change HTTP method
in form
* enforce POST method for webhook
* set default if method is empty
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/models/webhook.go b/models/webhook.go index 51b91879ee..48c4de2ea3 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -755,17 +755,15 @@ func prepareWebhooks(e Engine, repo *Repository, event HookEventType, p api.Payl func (t *HookTask) deliver() { t.IsDelivered = true - t.RequestInfo = &HookRequest{ - Headers: map[string]string{}, - } - t.ResponseInfo = &HookResponse{ - Headers: map[string]string{}, - } timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second var req *httplib.Request - if t.HTTPMethod == http.MethodPost { + switch t.HTTPMethod { + case "": + log.Info("HTTP Method for webhook %d empty, setting to POST as default", t.ID) + fallthrough + case http.MethodPost: req = httplib.Post(t.URL) switch t.ContentType { case ContentTypeJSON: @@ -773,10 +771,10 @@ func (t *HookTask) deliver() { case ContentTypeForm: req.Param("payload", t.PayloadContent) } - } else if t.HTTPMethod == http.MethodGet { + case http.MethodGet: req = httplib.Get(t.URL).Param("payload", t.PayloadContent) - } else { - t.ResponseInfo.Body = fmt.Sprintf("Invalid http method: %v", t.HTTPMethod) + default: + log.Error("Invalid http method for webhook: [%d] %v", t.ID, t.HTTPMethod) return } @@ -792,10 +790,17 @@ func (t *HookTask) deliver() { SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify}) // Record delivery information. + t.RequestInfo = &HookRequest{ + Headers: map[string]string{}, + } for k, vals := range req.Headers() { t.RequestInfo.Headers[k] = strings.Join(vals, ",") } + t.ResponseInfo = &HookResponse{ + Headers: map[string]string{}, + } + defer func() { t.Delivered = time.Now().UnixNano() if t.IsSucceed { |