mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 10:16:32 +00:00
Forward path and query string through proxy
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
@ -17,11 +17,12 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/openfaas/faas/gateway/metrics"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/openfaas/faas/gateway/metrics"
|
||||
"github.com/openfaas/faas/gateway/requests"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -90,8 +91,10 @@ func lookupInvoke(w http.ResponseWriter, r *http.Request, metrics metrics.Metric
|
||||
|
||||
if exists {
|
||||
defer trackTime(time.Now(), metrics, name)
|
||||
forwardReq := requests.NewForwardRequest(r.Method, *r.URL)
|
||||
|
||||
requestBody, _ := ioutil.ReadAll(r.Body)
|
||||
invokeService(w, r, metrics, name, requestBody, logger, proxyClient)
|
||||
invokeService(w, r, metrics, name, forwardReq, requestBody, logger, proxyClient)
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +107,7 @@ func lookupSwarmService(serviceName string, c *client.Client) (bool, error) {
|
||||
return len(services) > 0, err
|
||||
}
|
||||
|
||||
func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.MetricOptions, service string, requestBody []byte, logger *logrus.Logger, proxyClient *http.Client) {
|
||||
func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.MetricOptions, service string, forwardReq requests.ForwardRequest, requestBody []byte, logger *logrus.Logger, proxyClient *http.Client) {
|
||||
stamp := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
|
||||
defer func(when time.Time) {
|
||||
@ -131,7 +134,8 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri
|
||||
addr = entries[index].String()
|
||||
}
|
||||
}
|
||||
url := fmt.Sprintf("http://%s:%d/", addr, watchdogPort)
|
||||
|
||||
url := forwardReq.ToURL(addr, watchdogPort)
|
||||
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
fmt.Printf("[%s] Forwarding request [%s] to: %s\n", stamp, contentType, url)
|
||||
|
Reference in New Issue
Block a user