Skip to content
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion components/suggest/suggest-bench/benches/benchmark_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ fn run_benchmarks<B: BenchmarkWithInput, M: Measurement>(

fn setup_viaduct() {
static INIT: Once = Once::new();
INIT.call_once(|| viaduct_hyper::init_backend_hyper().expect("error initializing viaduct"));
INIT.call_once(|| {
viaduct_hyper::viaduct_init_backend_hyper().expect("error initializing viaduct")
});
}

criterion_group!(benches, geoname, ingest, query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
use suggest::benchmarks::ingest;

fn main() {
viaduct_hyper::init_backend_hyper().expect("Error initializing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initializing viaduct");
ingest::print_debug_ingestion_sizes()
}
2 changes: 1 addition & 1 deletion components/support/nimbus-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) static USER_AGENT: &str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

fn main() -> Result<()> {
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
let cmds = get_commands_from_cli(std::env::args_os())?;
for c in cmds {
let success = cmd::process_cmd(&c)?;
Expand Down
21 changes: 19 additions & 2 deletions components/support/viaduct-hyper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ struct HyperBackend {
}

/// Set the viaduct backend to the `hyper`-based one with HTTPS support.
///
/// Named `viaduct_init_backend_hyper` since that reads better on iOS/Swift where there aren't any
/// namespaces. Once we move to UniFII 0.31 we can use the renaming feature to do this instead.
#[uniffi::export]
pub fn init_backend_hyper() -> Result<()> {
pub fn viaduct_init_backend_hyper() -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not strictly necessary, but I think this will make the firefox-ios code more clear. If you just call initBackendHyper() it's not clear what the backend is for.

info!("initializing hyper backend");
// Create a multi-threaded runtime, with 1 worker thread.
//
Expand Down Expand Up @@ -80,10 +83,24 @@ impl Backend for HyperBackend {
/// This expects to be run in a `tokio::spawn` closure
async fn make_request_inner(
client: Client,
request: Request,
mut request: Request,
settings: ClientSettings,
) -> Result<Response> {
let mut url = request.url.clone();
// If the user-agent isn't set, try to get it from `GLOBAL_SETTINGS`.
// This only affects consumers who aren't yet using `Client` to make their requests, since
// `Client` already does this. Once we move all consumers over, we can remove this code.
if request.headers.get("User-Agent").is_none() {
let user_agent = settings.user_agent.or_else(|| {
viaduct::settings::GLOBAL_SETTINGS
.read()
.default_user_agent
.clone()
});
if let Some(ua) = user_agent {
request = request.header("User-Agent", ua)?;
}
}
let mut resp = make_single_request(&client, request.clone()).await?;
let mut redirect_count = 0;
while resp.status().is_redirection() {
Expand Down
3 changes: 3 additions & 0 deletions components/support/viaduct-hyper/uniffi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[bindings.swift]
ffi_module_name = "MozillaRustComponents"
ffi_module_filename = "viaducthyperFFI"
2 changes: 1 addition & 1 deletion examples/autofill-utils/src/autofill-utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn get_encryption_key(store: &Store, db_path: &str, opts: &Opts) -> Result<Strin

fn main() -> Result<()> {
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;

let opts = Opts::parse();
if !opts.no_logging {
Expand Down
2 changes: 1 addition & 1 deletion examples/example-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() -> ApiResult<()> {
init_logging(&cli);
// Applications must initialize viaduct for the HTTP client to work.
// This example uses the `hyper` backend because it's easy to setup.
viaduct_hyper::init_backend_hyper().expect("Error initializing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initializing viaduct");
let component = build_example_component()?;
println!();
match cli.command {
Expand Down
2 changes: 1 addition & 1 deletion examples/fxa-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum Command {
fn main() -> Result<()> {
let cli = Cli::parse();
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
if cli.log {
if cli.debug {
init_logging_with("fxa_client=debug");
Expand Down
2 changes: 1 addition & 1 deletion examples/merino-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum Commands {
fn main() -> Result<()> {
let cli = Cli::parse();

viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
let config = CuratedRecommendationsConfig {
base_host: cli.base_host.clone(),
user_agent_header: cli.user_agent.clone(),
Expand Down
2 changes: 1 addition & 1 deletion examples/nimbus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn main() -> Result<()> {
// Possible values are "info", "debug", "warn" and "error"
// Check [`env_logger`](https://docs.rs/env_logger/) for more details
error_support::init_for_tests_with_level(error_support::Level::Info);
viaduct_hyper::init_backend_hyper().expect("Error initalizing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initalizing viaduct");

// Initiate the matches for the command line arguments
let args = Args::parse();
Expand Down
2 changes: 1 addition & 1 deletion examples/places-utils/src/places-utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn sync(
nsyncs: u32,
wait: u64,
) -> Result<()> {
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;

let cli_fxa = get_cli_fxa(get_default_fxa_config(), &cred_file, &[SYNC_SCOPE])?;

Expand Down
2 changes: 1 addition & 1 deletion examples/push-livetest/src/livetest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use push::{BridgeType, PushConfiguration, PushManager};
*/
fn test_live_server() {
let tempdir = tempfile::tempdir().unwrap();
viaduct_hyper::init_backend_hyper().expect("Error initializing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initializing viaduct");

let push_config = PushConfiguration {
server_host: "localhost:8082".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/relay-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
init_logging(&cli);

viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;

let token = prompt_token()?;
let client = RelayClient::new("https://relay.firefox.com".to_string(), Some(token));
Expand Down
2 changes: 1 addition & 1 deletion examples/relevancy-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Cli {
fn main() -> Result<()> {
let cli = Cli::parse();
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
if let Some(dir) = std::path::PathBuf::from(CREDENTIALS_PATH).parent() {
std::fs::create_dir_all(dir)?;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-settings-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn main() -> Result<()> {
DEFAULT_LOG_FILTER
});
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
let service = build_service(&cli)?;
match cli.command {
Commands::Sync { collections } => sync(service, collections),
Expand Down
2 changes: 1 addition & 1 deletion examples/suggest-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn main() -> Result<()> {
DEFAULT_LOG_FILTER
});
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
let store = build_store(&cli)?;
match cli.command {
Commands::Ingest {
Expand Down
2 changes: 1 addition & 1 deletion examples/sync-pass/src/sync-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn do_sync(
#[allow(clippy::cognitive_complexity)] // FIXME
fn main() -> Result<()> {
cli_support::init_trace_logging();
viaduct_hyper::init_backend_hyper().expect("Error initializing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initializing viaduct");

let matches = clap::Command::new("sync_pass_sql")
.about("CLI login syncing tool")
Expand Down
2 changes: 1 addition & 1 deletion examples/tabs-sync/src/tabs-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn do_sync(

fn main() -> Result<()> {
nss::ensure_initialized();
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
cli_support::init_logging();
let opts = Opts::parse();

Expand Down
6 changes: 3 additions & 3 deletions examples/viaduct-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() -> Result<()> {

match backend_style {
BackendStyle::New => {
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
let settings = ClientSettings {
timeout: cli.timeout.unwrap_or(0) as u32,
..ClientSettings::default()
Expand All @@ -98,7 +98,7 @@ fn main() -> Result<()> {
print_response(client.send_sync(req));
}
BackendStyle::Bridged => {
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
if let Some(t) = cli.timeout {
set_old_global_timeout(t);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ fn run_ohttp_example(

match backend_style {
BackendStyle::New => {
viaduct_hyper::init_backend_hyper()?;
viaduct_hyper::viaduct_init_backend_hyper()?;
}
BackendStyle::Bridged => {
println!("OHTTP is not compatible with the bridged backend. Use --backend=new or omit the backend parameter.");
Expand Down
1 change: 1 addition & 0 deletions megazords/ios-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["staticlib", "rlib"]
[dependencies]
rust-log-forwarder = { path = "../../components/support/rust-log-forwarder" }
viaduct = { path = "../../components/viaduct", features = ["ohttp"] }
viaduct-hyper = { path = "../../components/support/viaduct-hyper" }
viaduct-reqwest = { path = "../../components/support/viaduct-reqwest" }
nimbus-sdk = { path = "../../components/nimbus" }
crashtest = { path = "../../components/crashtest" }
Expand Down
1 change: 1 addition & 0 deletions megazords/ios-rust/focus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["staticlib"]
[dependencies]
rust-log-forwarder = { path = "../../../components/support/rust-log-forwarder" }
viaduct = { path = "../../../components/viaduct" }
viaduct-hyper = { path = "../../../components/support/viaduct-hyper" }
viaduct-reqwest = { path = "../../../components/support/viaduct-reqwest" }
nimbus-sdk = { path = "../../../components/nimbus" }
error-support = { path = "../../../components/support/error" }
Expand Down
1 change: 1 addition & 0 deletions megazords/ios-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pub use sync_manager;
pub use tabs;
pub use tracing_support;
pub use viaduct;
pub use viaduct_hyper;
pub use viaduct_reqwest;
2 changes: 1 addition & 1 deletion testing/sync-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! cleanup_clients {
}

pub fn init_testing() {
viaduct_hyper::init_backend_hyper().expect("Error initializing viaduct");
viaduct_hyper::viaduct_init_backend_hyper().expect("Error initializing viaduct");
ensure_initialized();

// Enable backtraces.
Expand Down