api/vendor/github.com/labstack/echo/v4/middleware/proxy_1_11.go

25 lines
645 B
Go
Raw Normal View History

2019-03-24 09:13:40 +00:00
// +build go1.11
package middleware
import (
"fmt"
"net/http"
"net/http/httputil"
2019-05-07 19:42:24 +00:00
"github.com/labstack/echo/v4"
2019-03-24 09:13:40 +00:00
)
func proxyHTTP(tgt *ProxyTarget, c echo.Context, config ProxyConfig) http.Handler {
proxy := httputil.NewSingleHostReverseProxy(tgt.URL)
proxy.ErrorHandler = func(resp http.ResponseWriter, req *http.Request, err error) {
desc := tgt.URL.String()
if tgt.Name != "" {
desc = fmt.Sprintf("%s(%s)", tgt.Name, tgt.URL.String())
}
2019-10-23 21:11:40 +00:00
c.Set("_error", echo.NewHTTPError(http.StatusBadGateway, fmt.Sprintf("remote %s unreachable, could not forward: %v", desc, err)))
2019-03-24 09:13:40 +00:00
}
proxy.Transport = config.Transport
return proxy
}