Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): disable XML via environment variable #5100

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions google/cloud/storage/doc/storage-main.dox
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ which should give you a taste of the Cloud Storage C++ client library API.
- `CLOUD_STORAGE_TESTBENCH_ENDPOINT=...` override the default endpoint used by
the library, intended for testing only.

### Experimental

- `GOOGLE_CLOUD_CPP_STORAGE_REST_CONFIG=...` configuration for the REST
protocol, currently only the `disable-xml` value has any effect. Sometimes
the application developer may want to test using an emulator that does not
support XML, while the library defaults to XML for some media operations.

- `GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG=...` used with
`google::cloud::storage_experimental::DefaultGrpcClient()` to configure
configure the gRPC protocol. Setting this to `media` enables gRPC for just
media operations (reading and writing data), while setting this to `metadata`
enables gRPC for all operations. Note that gRPC support is an early access
program, contact Google Cloud support for details.

### Using GOOGLE_CLOUD_PROJECT to set the default project

Some of the GCS APIs need a [project][project-definition-link] as a parameter.
Expand Down
12 changes: 10 additions & 2 deletions google/cloud/storage/internal/curl_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ StatusOr<ReturnType> ParseFromHttpResponse(StatusOr<HttpResponse> response) {
return ReturnType::FromHttpResponse(response->payload);
}

bool XmlEnabled() {
auto const config =
google::cloud::internal::GetEnv("GOOGLE_CLOUD_CPP_STORAGE_REST_CONFIG")
.value_or("");
return config != "disable-xml";
}

} // namespace

Status CurlClient::SetupBuilderCommon(CurlRequestBuilder& builder,
Expand Down Expand Up @@ -237,6 +244,7 @@ CurlClient::CurlClient(ClientOptions options)
xml_download_endpoint_(XmlDownloadEndpoint(options_)),
xml_download_host_(ExtractUrlHostpart(xml_download_endpoint_)),
iam_endpoint_(IamEndpoint(options_)),
xml_enabled_(XmlEnabled()),
generator_(google::cloud::internal::MakeDefaultPRNG()),
storage_factory_(CreateHandleFactory(options_)),
upload_factory_(CreateHandleFactory(options_)),
Expand Down Expand Up @@ -495,7 +503,7 @@ StatusOr<ObjectMetadata> CurlClient::InsertObjectMedia(
}

// Unless the request uses a feature that disables it, prefer to use XML.
if (!request.HasOption<IfMetagenerationNotMatch>() &&
if (xml_enabled_ && !request.HasOption<IfMetagenerationNotMatch>() &&
!request.HasOption<IfGenerationNotMatch>() &&
!request.HasOption<QuotaUser>() && !request.HasOption<UserIp>() &&
!request.HasOption<Projection>() && request.HasOption<Fields>() &&
Expand Down Expand Up @@ -553,7 +561,7 @@ StatusOr<ObjectMetadata> CurlClient::GetObjectMetadata(

StatusOr<std::unique_ptr<ObjectReadSource>> CurlClient::ReadObject(
ReadObjectRangeRequest const& request) {
if (!request.HasOption<IfMetagenerationNotMatch>() &&
if (xml_enabled_ && !request.HasOption<IfMetagenerationNotMatch>() &&
!request.HasOption<IfGenerationNotMatch>() &&
!request.HasOption<QuotaUser>() && !request.HasOption<UserIp>()) {
return ReadObjectXml(request);
Expand Down
1 change: 1 addition & 0 deletions google/cloud/storage/internal/curl_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class CurlClient : public RawClient,
std::string const xml_download_endpoint_;
std::string const xml_download_host_;
std::string const iam_endpoint_;
bool const xml_enabled_;

std::mutex mu_;
google::cloud::internal::DefaultPRNG generator_; // GUARDED_BY(mu_);
Expand Down