diff options
author | Chris <ccbrown112@gmail.com> | 2018-02-12 18:36:39 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 18:36:39 -0600 |
commit | fbef16f8630f74248157c2cd9e546ece355c869a (patch) | |
tree | 95feb1a0b94f43fd38533adc508df2daf823ea86 /utils/api.go | |
parent | 56f49cf4860cfca51e852ec3e7d9df772d2b2060 (diff) | |
parent | 32c1f7be239ddb19d6c59b114d9ae1a543f8ba9c (diff) | |
download | chat-fbef16f8630f74248157c2cd9e546ece355c869a.tar.gz chat-fbef16f8630f74248157c2cd9e546ece355c869a.tar.bz2 chat-fbef16f8630f74248157c2cd9e546ece355c869a.zip |
Merge branch 'release-4.7' into rm-willnorris-proxy-support
Diffstat (limited to 'utils/api.go')
-rw-r--r-- | utils/api.go | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/utils/api.go b/utils/api.go index 51524074d..005c3284b 100644 --- a/utils/api.go +++ b/utils/api.go @@ -4,9 +4,6 @@ package utils import ( - "crypto" - "crypto/rand" - "encoding/base64" "fmt" "html/template" "net/http" @@ -35,25 +32,13 @@ func OriginChecker(allowedOrigins string) func(*http.Request) bool { } } -func RenderWebAppError(w http.ResponseWriter, r *http.Request, err *model.AppError, s crypto.Signer) { - RenderWebError(w, r, err.StatusCode, url.Values{ - "message": []string{err.Message}, - }, s) -} - -func RenderWebError(w http.ResponseWriter, r *http.Request, status int, params url.Values, s crypto.Signer) { - queryString := params.Encode() - - h := crypto.SHA256 - sum := h.New() - sum.Write([]byte("/error?" + queryString)) - signature, err := s.Sign(rand.Reader, sum.Sum(nil), h) - if err != nil { - http.Error(w, "", http.StatusInternalServerError) - return +func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) { + status := http.StatusTemporaryRedirect + if err.StatusCode != http.StatusInternalServerError { + status = err.StatusCode } - destination := strings.TrimRight(GetSiteURL(), "/") + "/error?" + queryString + "&s=" + base64.URLEncoding.EncodeToString(signature) + destination := strings.TrimRight(GetSiteURL(), "/") + "/error?message=" + url.QueryEscape(err.Message) if status >= 300 && status < 400 { http.Redirect(w, r, destination, status) return |