@@ -30,16 +30,17 @@ var _ = Describe("HTTP Upstream Suite", func() {
3030 falsum := false
3131
3232 type httpUpstreamTableInput struct {
33− id string
34− serverAddr *string
35− target string
36− method string
37− body []byte
38− signatureData *options.SignatureData
39− existingHeaders map[string]string
40− expectedResponse testHTTPResponse
41− expectedUpstream string
42− errorHandler ProxyErrorHandler
33+ id string
34+ serverAddr *string
35+ target string
36+ method string
37+ body []byte
38+ passUpstreamHostHeader bool
39+ signatureData *options.SignatureData
40+ existingHeaders map[string]string
41+ expectedResponse testHTTPResponse
42+ expectedUpstream string
43+ errorHandler ProxyErrorHandler
4344 }
4445
4546 DescribeTable("HTTP Upstream ServeHTTP",
@@ -52,6 +53,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
5253 for key, value := range in.existingHeaders {
5354 req.Header.Add(key, value)
5455 }
56+ if host := req.Header.Get("Host"); host != "" {
57+ req.Host = host
58+ }
5559
5660 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
5761 rw := httptest.NewRecorder()
@@ -60,7 +64,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
6064
6165 upstream := options.Upstream{
6266 ID: in.id,
63− PassHostHeader: &truth,
67+ PassHostHeader: &in.passUpstreamHostHeader,
6468 ProxyWebSockets: &falsum,
6569 InsecureSkipTLSVerify: false,
6670 FlushInterval: &flush,
@@ -140,6 +144,29 @@ var _ = Describe("HTTP Upstream Suite", func() {
140144 },
141145 expectedUpstream: "encodedSlashes",
142146 }),
147+ Entry("request a path with an empty query string", &httpUpstreamTableInput{
148+ id: "default",
149+ serverAddr: &serverAddr,
150+ target: "http://example.localhost/foo?",
151+ method: "GET",
152+ body: []byte{},
153+ errorHandler: nil,
154+ expectedResponse: testHTTPResponse{
155+ code: 200,
156+ header: map[string][]string{
157+ contentType: {applicationJSON},
158+ },
159+ request: testHTTPRequest{
160+ Method: "GET",
161+ URL: "http://example.localhost/foo?",
162+ Header: map[string][]string{},
163+ Body: []byte{},
164+ Host: "example.localhost",
165+ RequestURI: "http://example.localhost/foo?",
166+ },
167+ },
168+ expectedUpstream: "default",
169+ }),
143170 Entry("when the request has a body", &httpUpstreamTableInput{
144171 id: "requestWithBody",
145172 serverAddr: &serverAddr,
@@ -257,6 +284,33 @@ var _ = Describe("HTTP Upstream Suite", func() {
257284 },
258285 expectedUpstream: "existingHeaders",
259286 }),
287+ Entry("when passing the existing host header", &httpUpstreamTableInput{
288+ id: "passExistingHostHeader",
289+ serverAddr: &serverAddr,
290+ target: "/existingHostHeader",
291+ method: "GET",
292+ body: []byte{},
293+ errorHandler: nil,
294+ passUpstreamHostHeader: true,
295+ existingHeaders: map[string]string{
296+ "Host": "existing-host",
297+ },
298+ expectedResponse: testHTTPResponse{
299+ code: 200,
300+ header: map[string][]string{
301+ contentType: {applicationJSON},
302+ },
303+ request: testHTTPRequest{
304+ Method: "GET",
305+ URL: "/existingHostHeader",
306+ Header: map[string][]string{},
307+ Body: []byte{},
308+ Host: "existing-host",
309+ RequestURI: "/existingHostHeader",
310+ },
311+ },
312+ expectedUpstream: "passExistingHostHeader",
313+ }),
260314 )
261315
262316 It("ServeHTTP, when not passing a host header", func() {