Don't modify path in the proxy, strip prefix in the handler

This commit is contained in:
Łukasz Mierzwa
2018-01-06 17:28:03 -08:00
parent 3eb28b3a6f
commit db0d86f339

View File

@@ -5,7 +5,6 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
"github.com/cloudflare/unsee/internal/alertmanager"
"github.com/cloudflare/unsee/internal/config"
@@ -28,7 +27,6 @@ func NewAlertmanagerProxy(alertmanager *alertmanager.Alertmanager) (*httputil.Re
Director: func(req *http.Request) {
req.URL.Scheme = upstreamURL.Scheme
req.URL.Host = upstreamURL.Host
req.URL.Path = strings.TrimPrefix(req.URL.Path, proxyPathPrefix(alertmanager.Name))
// drop Accept-Encoding header so we always get uncompressed reponses from
// upstream, there's a gzip middleware that's global so we don't want it
// to gzip twice
@@ -50,7 +48,11 @@ func setupRouterProxyHandlers(router *gin.Engine, alertmanager *alertmanager.Ale
if err != nil {
return err
}
router.POST(fmt.Sprintf("%s/api/v1/silences", proxyPathPrefix(alertmanager.Name)), gin.WrapH(proxy))
router.DELETE(fmt.Sprintf("%s/api/v1/silence/*id", proxyPathPrefix(alertmanager.Name)), gin.WrapH(proxy))
router.POST(
fmt.Sprintf("%s/api/v1/silences", proxyPathPrefix(alertmanager.Name)),
gin.WrapH(http.StripPrefix(proxyPathPrefix(alertmanager.Name), proxy)))
router.DELETE(
fmt.Sprintf("%s/api/v1/silence/*id", proxyPathPrefix(alertmanager.Name)),
gin.WrapH(http.StripPrefix(proxyPathPrefix(alertmanager.Name), proxy)))
return nil
}