From bbb45b4e0d403b7aded61c30b1d7654cda93e937 Mon Sep 17 00:00:00 2001 From: steinfletcher Date: Mon, 22 Apr 2019 07:10:25 +0100 Subject: [PATCH] fallback to URL host if request host not defined --- apitest.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apitest.go b/apitest.go index e87f2e5..1cb123b 100644 --- a/apitest.go +++ b/apitest.go @@ -410,6 +410,14 @@ type mockInteraction struct { timestamp time.Time } +func (r *mockInteraction) GetRequestHost() string { + host := r.request.Host + if host == "" { + host = r.request.URL.Host + } + return host +} + func (a *APITest) report() { var capturedInboundReq *http.Request var capturedFinalRes *http.Response @@ -454,13 +462,13 @@ func (a *APITest) report() { for _, interaction := range capturedMockInteractions { a.recorder.AddHttpRequest(HttpRequest{ Source: quoted(systemUnderTestDefaultName), - Target: quoted(interaction.request.Host), + Target: quoted(interaction.GetRequestHost()), Value: interaction.request, Timestamp: interaction.timestamp, }) if interaction.response != nil { a.recorder.AddHttpResponse(HttpResponse{ - Source: quoted(interaction.request.Host), + Source: quoted(interaction.GetRequestHost()), Target: quoted(systemUnderTestDefaultName), Value: interaction.response, Timestamp: interaction.timestamp,