diff --git a/core/handlers/v2/simulation_views_v1.go b/core/handlers/v2/simulation_views_v1.go index 7c8fd415a..ea33b4cd2 100644 --- a/core/handlers/v2/simulation_views_v1.go +++ b/core/handlers/v2/simulation_views_v1.go @@ -75,7 +75,6 @@ type RequestDetailsView struct { RequestType *string `json:"requestType,omitempty"` Path *string `json:"path"` Method *string `json:"method"` - Host *string `json:"host"` Destination *string `json:"destination"` Scheme *string `json:"scheme"` Query *string `json:"query"` @@ -91,9 +90,6 @@ func (this RequestDetailsView) GetPath() *string { return this.Path } // Gets Method - required for interfaces.RequestMatcher func (this RequestDetailsView) GetMethod() *string { return this.Method } -// Gets Host - required for interfaces.RequestMatcher -func (this RequestDetailsView) GetHost() *string { return this.Host } - // Gets Destination - required for interfaces.RequestMatcher func (this RequestDetailsView) GetDestination() *string { return this.Destination } diff --git a/core/interfaces/interfaces.go b/core/interfaces/interfaces.go index d1a1f6453..2da9f56cb 100644 --- a/core/interfaces/interfaces.go +++ b/core/interfaces/interfaces.go @@ -8,7 +8,6 @@ type RequestResponsePair interface { type Request interface { GetPath() *string GetMethod() *string - GetHost() *string GetDestination() *string GetScheme() *string GetQuery() *string diff --git a/core/matching/strongest_match_strategy_test.go b/core/matching/strongest_match_strategy_test.go index d25e81c73..7899fb784 100644 --- a/core/matching/strongest_match_strategy_test.go +++ b/core/matching/strongest_match_strategy_test.go @@ -1396,7 +1396,6 @@ func Test_ShouldReturnMessageForClosestMiss(t *testing.T) { RequestDetails: models.RequestDetails{ Path: "path", Method: "method", - Host: "host", Destination: "destination", Scheme: "scheme", Query: map[string][]string{ @@ -1479,7 +1478,6 @@ The following request was made, but was not matched by Hoverfly: { "Path": "path", "Method": "method", - "Host": "host", "Destination": "destination", "Scheme": "scheme", "Query": { diff --git a/core/middleware/remote_middleware_test.go b/core/middleware/remote_middleware_test.go index 016b988a1..7b31fc360 100644 --- a/core/middleware/remote_middleware_test.go +++ b/core/middleware/remote_middleware_test.go @@ -58,7 +58,7 @@ func Test_Middleware_executeMiddlewareRemotely_ReturnsErrorIfDoesntGetA200_AndSa Expect(err.Error()).To(ContainSubstring("Error when communicating with remote middleware: received 404")) Expect(err.Error()).To(ContainSubstring("URL: " + server.URL)) Expect(err.Error()).To(ContainSubstring("STDIN:")) - Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","host":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) + Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) Expect(newPair).To(Equal(originalPair)) } @@ -87,7 +87,7 @@ func Test_Middleware_executeMiddlewareRemotely_ReturnsErrorIfNoRequestResponsePa Expect(err.Error()).To(ContainSubstring("Error when trying to serialize response from remote middleware")) Expect(err.Error()).To(ContainSubstring("URL: " + server.URL)) Expect(err.Error()).To(ContainSubstring("STDIN:")) - Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","host":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) + Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) Expect(untouchedPair).To(Equal(originalPair)) } @@ -111,7 +111,7 @@ func Test_Middleware_executeMiddlewareRemotely_ReturnsError_WebsiteIsUnreachable Expect(err.Error()).To(ContainSubstring(`Post "[]somemadeupwebsite": unsupported protocol scheme`)) Expect(err.Error()).To(ContainSubstring("URL: []somemadeupwebsite")) Expect(err.Error()).To(ContainSubstring("STDIN:")) - Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","host":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) + Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) Expect(untouchedPair).To(Equal(originalPair)) @@ -123,7 +123,7 @@ func Test_Middleware_executeMiddlewareRemotely_ReturnsError_WebsiteIsUnreachable Expect(err.Error()).To(MatchRegexp(`Post "http://localhost:4321/spectolabs/hoverfly": dial tcp .+:4321: connect: connection refused`)) Expect(err.Error()).To(ContainSubstring("URL: http://localhost:4321/spectolabs/hoverfly")) Expect(err.Error()).To(ContainSubstring("STDIN:")) - Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","host":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) + Expect(err.Error()).To(ContainSubstring(`{"response":{"status":0,"body":"Normal body","encodedBody":false},"request":{"path":"","method":"","destination":"","scheme":"","query":"","formData":null,"body":"","headers":null}}`)) Expect(untouchedPair).To(Equal(originalPair)) } diff --git a/core/middleware/views.go b/core/middleware/views.go index 476355236..05c29adb3 100644 --- a/core/middleware/views.go +++ b/core/middleware/views.go @@ -23,7 +23,6 @@ type RequestDetailsView struct { RequestType *string `json:"requestType"` Path *string `json:"path"` Method *string `json:"method"` - Host *string `json:"host"` Destination *string `json:"destination"` Scheme *string `json:"scheme"` Query *string `json:"query"` @@ -36,8 +35,6 @@ func (this RequestDetailsView) GetPath() *string { return this.Path } func (this RequestDetailsView) GetMethod() *string { return this.Method } -func (this RequestDetailsView) GetHost() *string { return this.Host } - func (this RequestDetailsView) GetDestination() *string { return this.Destination } func (this RequestDetailsView) GetScheme() *string { return this.Scheme } diff --git a/core/models/payload.go b/core/models/payload.go index 6ad6785dc..393599224 100644 --- a/core/models/payload.go +++ b/core/models/payload.go @@ -41,7 +41,6 @@ func NewRequestDetailsFromRequest(data interfaces.Request) RequestDetails { return RequestDetails{ Path: util.PointerToString(data.GetPath()), Method: util.PointerToString(data.GetMethod()), - Host: util.PointerToString(data.GetHost()), Destination: util.PointerToString(data.GetDestination()), Scheme: util.PointerToString(data.GetScheme()), Query: query, @@ -54,7 +53,6 @@ func NewRequestDetailsFromRequest(data interfaces.Request) RequestDetails { type RequestDetails struct { Path string Method string - Host string Destination string Scheme string Query map[string][]string @@ -97,7 +95,6 @@ func NewRequestDetailsFromHttpRequest(req *http.Request) (RequestDetails, error) requestDetails := RequestDetails{ Path: urlPath, Method: req.Method, - Host: req.Host, Destination: strings.ToLower(req.Host), Scheme: scheme, Query: req.URL.Query(), @@ -128,7 +125,6 @@ func (this *RequestDetails) ConvertToRequestDetailsView() v2.RequestDetailsView return v2.RequestDetailsView{ Path: &this.Path, Method: &this.Method, - Host: &this.Host, Destination: &this.Destination, Scheme: &this.Scheme, Query: &queryString, diff --git a/core/models/payload_test.go b/core/models/payload_test.go index 01182115a..373993276 100644 --- a/core/models/payload_test.go +++ b/core/models/payload_test.go @@ -141,7 +141,6 @@ func TestRequestResponsePair_ConvertToRequestResponsePairView_WithPlainTextRespo Request: models.RequestDetails{ Path: "/", Method: "GET", - Host: "www.foo.com", Destination: "/", Scheme: "scheme", Query: map[string][]string{}, @@ -160,7 +159,6 @@ func TestRequestResponsePair_ConvertToRequestResponsePairView_WithPlainTextRespo Request: v2.RequestDetailsView{ Path: StringToPointer("/"), Method: StringToPointer("GET"), - Host: StringToPointer("www.foo.com"), Destination: StringToPointer("/"), Scheme: StringToPointer("scheme"), Query: StringToPointer(""), @@ -181,7 +179,6 @@ func TestRequestResponsePair_ConvertToRequestResponsePairView_WithGzippedRespons Request: models.RequestDetails{ Path: "/", Method: "GET", - Host: "www.foo.com", Destination: "/", Scheme: "scheme", Query: map[string][]string{}, @@ -201,7 +198,6 @@ func TestRequestResponsePair_ConvertToRequestResponsePairView_WithGzippedRespons Request: v2.RequestDetailsView{ Path: StringToPointer("/"), Method: StringToPointer("GET"), - Host: StringToPointer("www.foo.com"), Destination: StringToPointer("/"), Scheme: StringToPointer("scheme"), Query: StringToPointer(""), diff --git a/core/templating/templating.go b/core/templating/templating.go index da82ac463..91eb8d672 100644 --- a/core/templating/templating.go +++ b/core/templating/templating.go @@ -113,7 +113,7 @@ func (t *Templator) NewTemplatingData(requestDetails *models.RequestDetails, lit FormData: requestDetails.FormData, body: requestDetails.Body, Method: requestDetails.Method, - Host: requestDetails.Host, + Host: requestDetails.Destination, }, Literals: literalMap, Vars: variableMap, diff --git a/functional-tests/core/ft_templated_response_test.go b/functional-tests/core/ft_templated_response_test.go index 55b986eae..ba378c271 100644 --- a/functional-tests/core/ft_templated_response_test.go +++ b/functional-tests/core/ft_templated_response_test.go @@ -444,6 +444,18 @@ var _ = Describe("When I run Hoverfly", func() { Expect(string(body)).To(Equal("param")) }) + It("Request.Host", func() { + hoverfly.ImportSimulation(testdata.TemplatingRequest) + + resp := hoverfly.Proxy(sling.New().Get("http://test-server.com/Request.Host")) + Expect(resp.StatusCode).To(Equal(200)) + + body, err := io.ReadAll(resp.Body) + Expect(err).To(BeNil()) + + Expect(string(body)).To(Equal("test-server.com")) + }) + It("Gloabl literals and variables", func() { hoverfly.ImportSimulation(testdata.TemplatingRequest) resp := hoverfly.Proxy(sling.New().Post("http://test-server.com/global").BodyJSON(map[string]string{ diff --git a/functional-tests/testdata/templating_request.go b/functional-tests/testdata/templating_request.go index 6f70ccd68..366da6f90 100644 --- a/functional-tests/testdata/templating_request.go +++ b/functional-tests/testdata/templating_request.go @@ -147,6 +147,22 @@ var TemplatingRequest = `{ "templated": true } }, + { + "request": { + "path": [ + { + "matcher": "exact", + "value": "/Request.Host" + } + ] + }, + "response": { + "status": 200, + "body": "{{ Request.Host }}", + "encodedBody": false, + "templated": true + } + }, { "request": { "path": [