From 85aa3d664c32af0532113f554002a5d3192faf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 26 Jun 2018 23:04:06 +0200 Subject: MM-11034: Reply properly to incomming webhooks on errors (#9010) --- web/handlers.go | 2 +- web/web.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/web/handlers.go b/web/handlers.go index c12466fee..c089f460b 100644 --- a/web/handlers.go +++ b/web/handlers.go @@ -157,7 +157,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.Err.IsOAuth = false } - if IsApiCall(c.App, r) || len(r.Header.Get("X-Mobile-App")) > 0 { + if IsApiCall(c.App, r) || IsWebhookCall(c.App, r) || len(r.Header.Get("X-Mobile-App")) > 0 { w.WriteHeader(c.Err.StatusCode) w.Write([]byte(c.Err.ToJson())) } else { diff --git a/web/web.go b/web/web.go index 479f439fb..f41854cbd 100644 --- a/web/web.go +++ b/web/web.go @@ -73,7 +73,13 @@ func Handle404(a *app.App, w http.ResponseWriter, r *http.Request) { func IsApiCall(a *app.App, r *http.Request) bool { subpath, _ := utils.GetSubpathFromConfig(a.Config()) - return strings.Index(r.URL.Path, path.Join(subpath, "api")+"/") == 0 + return strings.HasPrefix(r.URL.Path, path.Join(subpath, "api")+"/") +} + +func IsWebhookCall(a *app.App, r *http.Request) bool { + subpath, _ := utils.GetSubpathFromConfig(a.Config()) + + return strings.HasPrefix(r.URL.Path, path.Join(subpath, "hooks")+"/") } func ReturnStatusOK(w http.ResponseWriter) { -- cgit v1.2.3-1-g7c22