Skip to content

Commit

Permalink
tweak normalization, allow http with a port through
Browse files Browse the repository at this point in the history
  • Loading branch information
austin-denoble committed Aug 1, 2024
1 parent c9a619b commit 6437ad4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 9 additions & 3 deletions pinecone/index_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
10 changes: 7 additions & 3 deletions pinecone/index_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down

0 comments on commit 6437ad4

Please sign in to comment.