Skip to content

Commit

Permalink
feat(storage): support custom hostname for VirtualHostedStyle SignedU…
Browse files Browse the repository at this point in the history
…RLs (#9348)
  • Loading branch information
BrennaEpp authored Feb 1, 2024
1 parent f127b46 commit 7eec40e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions storage/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,8 @@ func TestBucketSignedURL_Endpoint_Emulator_Host(t *testing.T) {
},
{
desc: "VirtualHostedStyle - endpoint overrides emulator",
emulatorHost: "localhost:9000",
endpoint: &localhost6000Https,
emulatorHost: "localhost:8000",
endpoint: &localhost9000,
now: expires.Add(-24 * time.Hour),
opts: &SignedURLOptions{
GoogleAccessID: "xxx@clientid",
Expand Down
8 changes: 8 additions & 0 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,14 @@ func TestIntegration_SignedURL(t *testing.T) {
headers: map[string][]string{"X-Goog-Foo": {"bar baz"}},
fail: true,
},
{
desc: "Virtual hosted style with custom hostname",
opts: SignedURLOptions{
Style: VirtualHostedStyle(),
Hostname: "storage.googleapis.com:443",
},
fail: false,
},
{
desc: "Hostname v4",
opts: SignedURLOptions{
Expand Down
8 changes: 6 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ func (s pathStyle) host(hostname, bucket string) string {
return "storage.googleapis.com"
}

func (s virtualHostedStyle) host(_, bucket string) string {
func (s virtualHostedStyle) host(hostname, bucket string) string {
if hostname != "" {
return bucket + "." + stripScheme(hostname)
}

if host := os.Getenv("STORAGE_EMULATOR_HOST"); host != "" {
return bucket + "." + stripScheme(host)
}
Expand Down Expand Up @@ -457,7 +461,7 @@ type SignedURLOptions struct {

// Hostname sets the host of the signed URL. This field overrides any
// endpoint set on a storage Client or through STORAGE_EMULATOR_HOST.
// Only compatible with PathStyle URLStyle.
// Only compatible with PathStyle and VirtualHostedStyle URLStyles.
// Optional.
Hostname string
}
Expand Down

0 comments on commit 7eec40e

Please sign in to comment.