Skip to content

Commit d6c7833

Browse files
authored
Merge pull request #266 from nyannyacha/fix-sb-ua
fix: make the runtime user agent respect the convention
2 parents 705db6e + 0640f70 commit d6c7833

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

crates/base/src/deno_runtime.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use deno_tls::rustls::RootCertStore;
1818
use deno_tls::RootCertStoreProvider;
1919
use futures_util::future::poll_fn;
2020
use log::{error, trace};
21-
use once_cell::sync::OnceCell;
21+
use once_cell::sync::{Lazy, OnceCell};
2222
use sb_core::conn_sync::ConnSync;
2323
use sb_core::util::sync::AtomicFlag;
2424
use serde::de::DeserializeOwned;
@@ -80,6 +80,14 @@ fn get_error_class_name(e: &AnyError) -> &'static str {
8080
}
8181

8282
pub static MAYBE_DENO_VERSION: OnceCell<String> = OnceCell::new();
83+
static SUPABASE_UA: Lazy<String> = Lazy::new(|| {
84+
let deno_version = MAYBE_DENO_VERSION.get().map(|it| &**it).unwrap_or("1.0.0");
85+
let supabase_version = option_env!("GIT_V_TAG").unwrap_or("0.1.0");
86+
format!(
87+
"Deno/{} (variant; SupabaseEdgeRuntime/{})",
88+
deno_version, supabase_version
89+
)
90+
});
8391

8492
pub struct DenoRuntime {
8593
pub js_runtime: JsRuntime,
@@ -108,7 +116,6 @@ impl DenoRuntime {
108116
..
109117
} = opts;
110118

111-
let user_agent = "supabase-edge-runtime".to_string();
112119
let base_dir_path = std::env::current_dir().map(|p| p.join(&service_path))?;
113120
let base_url = Url::from_directory_path(&base_dir_path).unwrap();
114121

@@ -250,12 +257,12 @@ impl DenoRuntime {
250257
deno_webgpu::deno_webgpu::init_ops(),
251258
deno_canvas::deno_canvas::init_ops(),
252259
deno_fetch::deno_fetch::init_ops::<Permissions>(deno_fetch::Options {
253-
user_agent: user_agent.clone(),
260+
user_agent: SUPABASE_UA.clone(),
254261
root_cert_store_provider: Some(root_cert_store_provider.clone()),
255262
..Default::default()
256263
}),
257264
deno_websocket::deno_websocket::init_ops::<Permissions>(
258-
user_agent,
265+
SUPABASE_UA.clone(),
259266
Some(root_cert_store_provider.clone()),
260267
None,
261268
),

crates/sb_core/js/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ globalThis.bootstrapSBEdge = (opts, isUserWorker, isEventsWorker, edgeRuntimeVer
336336
ObjectDefineProperty(globalThis, 'Deno', readOnly(denoOverrides));
337337

338338
setNumCpus(1); // explicitly setting no of CPUs to 1 (since we don't allow workers)
339-
setUserAgent('Supabase Edge Runtime');
339+
setUserAgent(`Deno/${globalThis.DENO_VERSION} (variant; SupabaseEdgeRuntime/${globalThis.SUPABASE_VERSION})`);
340340
setLanguage('en');
341341

342342
if (isUserWorker) {

0 commit comments

Comments
 (0)