diff --git a/storage/bucket.go b/storage/bucket.go index 58ffb138f8dd..eb1feba22ea7 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -178,7 +178,7 @@ func (b *BucketHandle) SignedURL(object string, opts *SignedURLOptions) (string, if newopts.Hostname == "" { // Extract the correct host from the readhost set on the client - newopts.Hostname = b.c.readHost + newopts.Hostname = b.c.xmlHost } if opts.GoogleAccessID != "" && (opts.SignBytes != nil || len(opts.PrivateKey) > 0) { @@ -226,7 +226,7 @@ func (b *BucketHandle) GenerateSignedPostPolicyV4(object string, opts *PostPolic if newopts.Hostname == "" { // Extract the correct host from the readhost set on the client - newopts.Hostname = b.c.readHost + newopts.Hostname = b.c.xmlHost } if opts.GoogleAccessID != "" && (opts.SignRawBytes != nil || opts.SignBytes != nil || len(opts.PrivateKey) > 0) { diff --git a/storage/http_client.go b/storage/http_client.go index 4ca0e02bfd81..874be49db384 100644 --- a/storage/http_client.go +++ b/storage/http_client.go @@ -49,7 +49,7 @@ import ( type httpStorageClient struct { creds *google.Credentials hc *http.Client - readHost string + xmlHost string raw *raw.Service scheme string settings *settings @@ -123,7 +123,7 @@ func newHTTPStorageClient(ctx context.Context, opts ...storageOption) (storageCl if err != nil { return nil, fmt.Errorf("storage client: %w", err) } - // Update readHost and scheme with the chosen endpoint. + // Update xmlHost and scheme with the chosen endpoint. u, err := url.Parse(ep) if err != nil { return nil, fmt.Errorf("supplied endpoint %q is not valid: %w", ep, err) @@ -132,7 +132,7 @@ func newHTTPStorageClient(ctx context.Context, opts ...storageOption) (storageCl return &httpStorageClient{ creds: creds, hc: hc, - readHost: u.Host, + xmlHost: u.Host, raw: rawService, scheme: u.Scheme, settings: s, @@ -792,7 +792,7 @@ func (c *httpStorageClient) NewRangeReader(ctx context.Context, params *newRange func (c *httpStorageClient) newRangeReaderXML(ctx context.Context, params *newRangeReaderParams, s *settings) (r *Reader, err error) { u := &url.URL{ Scheme: c.scheme, - Host: c.readHost, + Host: c.xmlHost, Path: fmt.Sprintf("/%s/%s", params.bucket, params.object), RawPath: fmt.Sprintf("/%s/%s", params.bucket, url.PathEscape(params.object)), } diff --git a/storage/storage.go b/storage/storage.go index d56e2c20d98f..ba485ddcdacb 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -109,8 +109,8 @@ type Client struct { raw *raw.Service // Scheme describes the scheme under the current host. scheme string - // ReadHost is the default host used on the reader. - readHost string + // xmlHost is the default host used for XML requests. + xmlHost string // May be nil. creds *google.Credentials retry *retryConfig @@ -199,7 +199,7 @@ func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error if err != nil { return nil, fmt.Errorf("storage client: %w", err) } - // Update readHost and scheme with the chosen endpoint. + // Update xmlHost and scheme with the chosen endpoint. u, err := url.Parse(ep) if err != nil { return nil, fmt.Errorf("supplied endpoint %q is not valid: %w", ep, err) @@ -211,12 +211,12 @@ func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error } return &Client{ - hc: hc, - raw: rawService, - scheme: u.Scheme, - readHost: u.Host, - creds: creds, - tc: tc, + hc: hc, + raw: rawService, + scheme: u.Scheme, + xmlHost: u.Host, + creds: creds, + tc: tc, }, nil } diff --git a/storage/storage_test.go b/storage/storage_test.go index 3bb8e04c0b9e..edceac229c04 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -2016,7 +2016,7 @@ func TestEmulatorWithCredentialsFile(t *testing.T) { // Create a client using a combination of custom endpoint and // STORAGE_EMULATOR_HOST env variable and verify that raw.BasePath (used -// for writes) and readHost and scheme (used for reads) are all set correctly. +// for writes) and xmlHost and scheme (used for reads) are all set correctly. func TestWithEndpoint(t *testing.T) { originalStorageEmulatorHost := os.Getenv("STORAGE_EMULATOR_HOST") testCases := []struct { @@ -2024,7 +2024,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint string StorageEmulatorHost string WantRawBasePath string - WantReadHost string + WantXMLHost string WantScheme string }{ { @@ -2032,7 +2032,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "", StorageEmulatorHost: "", WantRawBasePath: "https://storage.googleapis.com/storage/v1/", - WantReadHost: "storage.googleapis.com", + WantXMLHost: "storage.googleapis.com", WantScheme: "https", }, { @@ -2040,7 +2040,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "https://fake.gcs.com:8080/storage/v1", StorageEmulatorHost: "", WantRawBasePath: "https://fake.gcs.com:8080/storage/v1", - WantReadHost: "fake.gcs.com:8080", + WantXMLHost: "fake.gcs.com:8080", WantScheme: "https", }, { @@ -2048,7 +2048,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "http://fake.gcs.com:8080/storage/v1", StorageEmulatorHost: "", WantRawBasePath: "http://fake.gcs.com:8080/storage/v1", - WantReadHost: "fake.gcs.com:8080", + WantXMLHost: "fake.gcs.com:8080", WantScheme: "http", }, { @@ -2056,7 +2056,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "", StorageEmulatorHost: "http://emu.com", WantRawBasePath: "http://emu.com/storage/v1/", - WantReadHost: "emu.com", + WantXMLHost: "emu.com", WantScheme: "http", }, { @@ -2064,7 +2064,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "", StorageEmulatorHost: "emu.com", WantRawBasePath: "http://emu.com/storage/v1/", - WantReadHost: "emu.com", + WantXMLHost: "emu.com", WantScheme: "http", }, { @@ -2072,7 +2072,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "", StorageEmulatorHost: "localhost:9000", WantRawBasePath: "http://localhost:9000/storage/v1/", - WantReadHost: "localhost:9000", + WantXMLHost: "localhost:9000", WantScheme: "http", }, { @@ -2080,7 +2080,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "https://fake.gcs.com:8080/storage/v1", StorageEmulatorHost: "http://emu.com", WantRawBasePath: "https://fake.gcs.com:8080/storage/v1", - WantReadHost: "fake.gcs.com:8080", + WantXMLHost: "fake.gcs.com:8080", WantScheme: "https", }, { @@ -2088,7 +2088,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "http://fake.gcs.com:8080/storage/v1", StorageEmulatorHost: "https://emu.com", WantRawBasePath: "http://fake.gcs.com:8080/storage/v1", - WantReadHost: "fake.gcs.com:8080", + WantXMLHost: "fake.gcs.com:8080", WantScheme: "http", }, { @@ -2096,7 +2096,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "http://localhost:8080/storage/v1", StorageEmulatorHost: "https://localhost:9000", WantRawBasePath: "http://localhost:8080/storage/v1", - WantReadHost: "localhost:8080", + WantXMLHost: "localhost:8080", WantScheme: "http", }, { @@ -2104,7 +2104,7 @@ func TestWithEndpoint(t *testing.T) { CustomEndpoint: "http://localhost:8080/storage/v1", StorageEmulatorHost: "localhost:9000", WantRawBasePath: "http://localhost:8080/storage/v1", - WantReadHost: "localhost:8080", + WantXMLHost: "localhost:8080", WantScheme: "http", }, } @@ -2119,8 +2119,8 @@ func TestWithEndpoint(t *testing.T) { if c.raw.BasePath != tc.WantRawBasePath { t.Errorf("%s: raw.BasePath not set correctly\n\tgot %v, want %v", tc.desc, c.raw.BasePath, tc.WantRawBasePath) } - if c.readHost != tc.WantReadHost { - t.Errorf("%s: readHost not set correctly\n\tgot %v, want %v", tc.desc, c.readHost, tc.WantReadHost) + if c.xmlHost != tc.WantXMLHost { + t.Errorf("%s: xmlHost not set correctly\n\tgot %v, want %v", tc.desc, c.xmlHost, tc.WantXMLHost) } if c.scheme != tc.WantScheme { t.Errorf("%s: scheme not set correctly\n\tgot %v, want %v", tc.desc, c.scheme, tc.WantScheme) @@ -2132,7 +2132,7 @@ func TestWithEndpoint(t *testing.T) { // Create a client using a combination of custom endpoint and STORAGE_EMULATOR_HOST // env variable and verify that the client hits the correct endpoint for several // different operations performe in sequence. -// Verifies also that raw.BasePath, readHost and scheme are not changed +// Verifies also that raw.BasePath, xmlHost and scheme are not changed // after running the operations. func TestOperationsWithEndpoint(t *testing.T) { originalStorageEmulatorHost := os.Getenv("STORAGE_EMULATOR_HOST") @@ -2214,7 +2214,7 @@ func TestOperationsWithEndpoint(t *testing.T) { return } originalRawBasePath := c.raw.BasePath - originalReadHost := c.readHost + originalXMLHost := c.xmlHost originalScheme := c.scheme operations := []struct { @@ -2298,9 +2298,9 @@ func TestOperationsWithEndpoint(t *testing.T) { t.Errorf("raw.BasePath changed\n\tgot:\t\t%v\n\toriginal:\t%v", c.raw.BasePath, originalRawBasePath) } - if c.readHost != originalReadHost { - t.Errorf("readHost changed\n\tgot:\t\t%v\n\toriginal:\t%v", - c.readHost, originalReadHost) + if c.xmlHost != originalXMLHost { + t.Errorf("xmlHost changed\n\tgot:\t\t%v\n\toriginal:\t%v", + c.xmlHost, originalXMLHost) } if c.scheme != originalScheme { t.Errorf("scheme changed\n\tgot:\t\t%v\n\toriginal:\t%v",