diff --git a/CHANGELOG.md b/CHANGELOG.md index e427151c3..d35548a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,8 +31,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Renamed the sequence number struct tag to if_seq_no to fix optimistic concurrency control ([#166](https://github.com/opensearch-project/opensearch-go/pull/166)) - Fix `RetryOnConflict` on bulk indexer ([#215](https://github.com/opensearch-project/opensearch-go/pull/215)) + - Correct curl logging to emit the correct URL destination ([#101](https://github.com/opensearch-project/opensearch-go/pull/101)) ### Security -[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/2.1...HEAD \ No newline at end of file +[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/2.1...HEAD diff --git a/opensearchtransport/logger.go b/opensearchtransport/logger.go index 223b0165d..f089e9e63 100644 --- a/opensearchtransport/logger.go +++ b/opensearchtransport/logger.go @@ -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) diff --git a/opensearchtransport/logger_internal_test.go b/opensearchtransport/logger_internal_test.go index c5d7e7b67..27beae7b7 100644 --- a/opensearchtransport/logger_internal_test.go +++ b/opensearchtransport/logger_internal_test.go @@ -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]) } })