mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
6d9e043284
This reintroduces support for Go modules, as v4. CloseNotifier() is removed as it has been obsoleted, see https://golang.org/doc/go1.11#net/http It was already NOT working (not sending signals) as of 1.11 the functionality was gone, we merely deleted the functions that exposed it. If anyone still relies on it they should migrate to using `c.Request().Context().Done()` instead. Closes #1268, #1255
26 lines
652 B
Go
26 lines
652 B
Go
// +build go1.11
|
|
|
|
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
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())
|
|
}
|
|
c.Logger().Errorf("remote %s unreachable, could not forward: %v", desc, err)
|
|
c.Error(echo.NewHTTPError(http.StatusServiceUnavailable))
|
|
}
|
|
proxy.Transport = config.Transport
|
|
return proxy
|
|
}
|