Skip to content

Commit

Permalink
Correct CurlLogger's URL to actual destination
Browse files Browse the repository at this point in the history
The CurlLogger hardcodes `http://localhost:9200`. This change instead uses the given configuration values.

Signed-off-by: Daniel Kimsey <dkimsey@trustwave.com>
Signed-off-by: Daniel Kimsey <dekimsey@protonmail.com>
  • Loading branch information
dekimsey committed Nov 12, 2022
1 parent 6746799 commit 2c6469a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions opensearchtransport/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ func (l *CurlLogger) LogRoundTrip(req *http.Request, res *http.Response, err err
}
}

b.WriteString(" 'http://localhost:9200")
b.WriteString(req.URL.Path)
// If by some oddity we end up with a nil req.URL, we handle it gracefully.
if req.URL == nil {
b.WriteString(" '")
} else {
b.WriteString(fmt.Sprintf(" '%s://%s%s", req.URL.Scheme, req.URL.Host, req.URL.Path))
}
b.WriteString("?pretty")
if query != "" {
fmt.Fprintf(&b, "&%s", query)
Expand Down
4 changes: 2 additions & 2 deletions opensearchtransport/logger_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestTransportLogger(t *testing.T) {
Logger: &CurlLogger{Output: &dst, EnableRequestBody: true, EnableResponseBody: true},
})

req, _ := http.NewRequest("GET", "/abc?q=a,b", nil)
req, _ := http.NewRequest("GET", "http://fake.example.com:9200/abc?q=a,b", nil)
req.Body = ioutil.NopCloser(strings.NewReader(`{"query":"42"}`))

res, err := tp.Perform(req)
Expand All @@ -285,7 +285,7 @@ func TestTransportLogger(t *testing.T) {
t.Fatalf("Expected 9 lines, got %d", len(lines))
}

if !strings.Contains(lines[0], "curl -X GET 'http://localhost:9200/abc?pretty&q=a%2Cb'") {
if !strings.Contains(lines[0], "curl -X GET 'http://foo/abc?pretty&q=a%2Cb'") {
t.Errorf("Unexpected output: %s", lines[0])
}
})
Expand Down

0 comments on commit 2c6469a

Please # to comment.