From 6437ad4734f1674dbe847b67a6cbee5b1d462a5c Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Thu, 1 Aug 2024 17:42:26 -0400 Subject: [PATCH] tweak normalization, allow http with a port through --- pinecone/index_connection.go | 12 +++++++++--- pinecone/index_connection_test.go | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 5700214..cef58b9 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -1094,12 +1094,18 @@ func sparseValToGrpc(sv *SparseValues) *data.SparseValues { } func normalizeHost(host string) string { - // remove http:// or https:// from the host - host = strings.TrimPrefix(host, "http://") + hasPort := strings.Contains(host, ":") + + // remove https:// from the host host = strings.TrimPrefix(host, "https://") + // if plaintext without a port, strip http:// as well + if !hasPort { + host = strings.TrimPrefix(host, "http://") + } + // if a port was provided leave it, otherwise we append :443 - if !strings.Contains(host, ":") { + if !hasPort { host = host + ":443" } diff --git a/pinecone/index_connection_test.go b/pinecone/index_connection_test.go index 6a03db3..0bc0b94 100644 --- a/pinecone/index_connection_test.go +++ b/pinecone/index_connection_test.go @@ -1006,9 +1006,13 @@ func TestNormalizeHost(t *testing.T) { host: "https://this-is-my-host.io", expectedHost: "this-is-my-host.io:443", }, { - name: "port should be maintained", - host: "https://this-is-my-host.io:8080", - expectedHost: "this-is-my-host.io:8080", + name: "http:// scheme without a port should be removed", + host: "http://this-is-my-host.io", + expectedHost: "this-is-my-host.io:443", + }, { + name: "http:// scheme and port should be maintained", + host: "http://this-is-my-host.io:8080", + expectedHost: "http://this-is-my-host.io:8080", }, }