or
  // C++ SDK, etc.).
  context->AddMetadata(
      kXGoogAPIClientHeader,
      StringFormat("gl-objc/ fire/%s grpc/", kFirestoreVersionString));

  // This header is used to improve routing and project isolation by the
  // backend.
  const DatabaseId& db_id = database_info_->database_id();
  context->AddMetadata(kGoogleCloudResourcePrefix,
                       StringFormat("projects/%s/databases/%s",
                                    db_id.project_id(), db_id.database_id()));
  return context;
}

void GrpcConnection::EnsureActiveStub() {
  // TODO(varconst): find out in which cases a gRPC channel might shut down.
  // This might be overkill.
  if (!grpc_channel_ || grpc_channel_->GetState(/*try_to_connect=*/false) ==
                            GRPC_CHANNEL_SHUTDOWN) {
    LOG_DEBUG("Creating Firestore stub.");
    grpc_channel_ = CreateChannel();
    grpc_stub_ = absl::make_unique<grpc::GenericStub>(grpc_channel_);
  }
}

std::shared_ptr<grpc::Channel> GrpcConnection::CreateChannel() const {
  const std::string& host = database_info_->host();

  if (!HasSpecialConfig(host)) {
    std::string root_certificate = LoadGrpcRootCertificate();
    return grpc::CreateChannel(host, CreateSslCredentials(root_certificate));
  }

  const HostConfig& host_config = Config()[host];

  // For the case when `Settings.sslEnabled == false`.
  if (host_config.use_insecure_channel) {
    return grpc::CreateChannel(host, grpc::InsecureChannelCredentials());
  }

  // For tests only
  grpc::ChannelArguments args;
  args.SetSslTargetNameOverride(host_config.target_name);
  Path path = host_config.certificate_path;
  StatusOr<std::string> test_certificate = ReadFile(path);
  HARD_ASSERT(test_certificate.ok(),
              StringFormat("Unable to open root certificates at file path %s",
                           path.ToUtf8String())
                  .c_str());

  return grpc::CreateCustomChannel(
      host, CreateSslCredentials(test_certificate.ValueOrDie()), args);
}

std::unique_ptr<GrpcStream> GrpcConnection::CreateStream