diff --git a/mw_js_plugin.go b/mw_js_plugin.go index a110ddf86d8..8626572fa07 100644 --- a/mw_js_plugin.go +++ b/mw_js_plugin.go @@ -109,6 +109,10 @@ func (d *DynamicMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Reques } headers.Set("Host", host) } + scheme := "http" + if r.TLS != nil { + scheme = "https" + } requestData := MiniRequestObject{ Headers: headers, @@ -122,7 +126,7 @@ func (d *DynamicMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Reques DeleteParams: []string{}, Method: r.Method, RequestURI: r.RequestURI, - Scheme: r.URL.Scheme, + Scheme: scheme, } requestAsJson, err := json.Marshal(requestData) diff --git a/mw_js_plugin_test.go b/mw_js_plugin_test.go index d6da9cb6ce7..722261b74aa 100644 --- a/mw_js_plugin_test.go +++ b/mw_js_plugin_test.go @@ -320,7 +320,6 @@ func TestJSVMRequestScheme(t *testing.T) { Pre: true, } req := httptest.NewRequest("GET", "/foo", nil) - req.URL.Scheme = "http" jsvm := JSVM{} jsvm.Init(nil, logrus.NewEntry(log)) diff --git a/mw_virtual_endpoint.go b/mw_virtual_endpoint.go index cc7f920e24b..43c9018aaab 100644 --- a/mw_virtual_endpoint.go +++ b/mw_virtual_endpoint.go @@ -31,6 +31,7 @@ type RequestObject struct { Body string URL string Params map[string][]string + Scheme string } type ResponseObject struct { @@ -136,10 +137,15 @@ func (d *VirtualEndpoint) ServeHTTPForCache(w http.ResponseWriter, r *http.Reque } defer r.Body.Close() + scheme := "http" + if r.TLS != nil { + scheme = "https" + } requestData := RequestObject{ Headers: r.Header, Body: string(originalBody), URL: r.URL.Path, + Scheme: scheme, } // We need to copy the body _back_ for the decode