Skip to content

Commit b00234e

Browse files
authored
fix: align file fetcher's user agent (#632)
* fix: align file fetcher's user agent * stamp: oops * stamp: fix unit test
1 parent 26de1eb commit b00234e

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

cli/src/env.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub(super) fn resolve_deno_runtime_env() {
3333
})
3434
};
3535

36-
runtime::MAYBE_DENO_VERSION.get_or_init(|| deno::version().to_string());
37-
3836
resolve_boolish_env(
3937
"DENO_NO_DEPRECATION_WARNINGS",
4038
&runtime::SHOULD_DISABLE_DEPRECATED_API_WARNING,

crates/base/src/runtime/mod.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,6 @@ pub mod permissions;
133133

134134
const DEFAULT_ALLOC_CHECK_INT_MSEC: u64 = 1000;
135135

136-
static SUPABASE_UA: Lazy<String> = Lazy::new(|| {
137-
let deno_version =
138-
MAYBE_DENO_VERSION.get().map(|it| &**it).unwrap_or("1.0.0");
139-
let supabase_version = option_env!("GIT_V_TAG").unwrap_or("0.1.0");
140-
format!(
141-
// TODO: It should be changed to a well-known name for the ecosystem.
142-
"Deno/{} (variant; SupabaseEdgeRuntime/{})",
143-
deno_version, supabase_version
144-
)
145-
});
146-
147136
static ALLOC_CHECK_DUR: Lazy<Duration> = Lazy::new(|| {
148137
std::env::var("EDGE_RUNTIME_ALLOC_CHECK_INT")
149138
.ok()
@@ -159,7 +148,6 @@ pub static SHOULD_USE_VERBOSE_DEPRECATED_API_WARNING: OnceCell<bool> =
159148
OnceCell::new();
160149
pub static SHOULD_INCLUDE_MALLOCED_MEMORY_ON_MEMCHECK: OnceCell<bool> =
161150
OnceCell::new();
162-
pub static MAYBE_DENO_VERSION: OnceCell<String> = OnceCell::new();
163151

164152
pub static MAIN_WORKER_INITIAL_HEAP_SIZE_MIB: OnceCell<u64> = OnceCell::new();
165153
pub static MAIN_WORKER_MAX_HEAP_SIZE_MIB: OnceCell<u64> = OnceCell::new();
@@ -242,7 +230,6 @@ pub trait GetRuntimeContext {
242230
conf: &WorkerRuntimeOpts,
243231
use_inspector: bool,
244232
migrated: bool,
245-
version: Option<&str>,
246233
otel_config: Option<OtelConfig>,
247234
) -> impl Serialize {
248235
serde_json::json!({
@@ -252,11 +239,8 @@ pub trait GetRuntimeContext {
252239
"inspector": use_inspector,
253240
"migrated": migrated,
254241
"version": {
255-
"runtime": version.unwrap_or("0.1.0"),
256-
"deno": MAYBE_DENO_VERSION
257-
.get()
258-
.map(|it| &**it)
259-
.unwrap_or("UNKNOWN"),
242+
"runtime": deno::edge_runtime_version(),
243+
"deno": deno::version(),
260244
},
261245
"flags": {
262246
"SHOULD_DISABLE_DEPRECATED_API_WARNING":
@@ -770,13 +754,13 @@ where
770754
deno_canvas::deno_canvas::init_ops(),
771755
deno_fetch::deno_fetch::init_ops::<PermissionsContainer>(
772756
deno_fetch::Options {
773-
user_agent: SUPABASE_UA.clone(),
757+
user_agent: deno::versions::user_agent().to_string(),
774758
root_cert_store_provider: Some(root_cert_store_provider.clone()),
775759
..Default::default()
776760
},
777761
),
778762
deno_websocket::deno_websocket::init_ops::<PermissionsContainer>(
779-
SUPABASE_UA.clone(),
763+
deno::versions::user_agent().to_string(),
780764
Some(root_cert_store_provider.clone()),
781765
None,
782766
),
@@ -1036,7 +1020,6 @@ where
10361020
&conf,
10371021
has_inspector,
10381022
migrated,
1039-
option_env!("GIT_V_TAG"),
10401023
maybe_otel_config,
10411024
));
10421025

@@ -3065,7 +3048,10 @@ mod test {
30653048
.to_vec();
30663049
assert_eq!(
30673050
deno_version_array.first().unwrap().as_str().unwrap(),
3068-
"supabase-edge-runtime-0.1.0 (compatible with Deno vUNKNOWN)"
3051+
format!(
3052+
"supabase-edge-runtime-0.1.0 (compatible with Deno v{})",
3053+
deno::version()
3054+
)
30693055
);
30703056
assert_eq!(
30713057
deno_version_array.get(1).unwrap().as_str().unwrap(),

deno/http_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22

33
use crate::auth_tokens::AuthToken;
4-
use crate::versions::get_user_agent;
4+
use crate::versions::user_agent;
55

66
use cache_control::Cachability;
77
use cache_control::CacheControl;
@@ -245,7 +245,7 @@ impl HttpClientProvider {
245245
Entry::Occupied(entry) => Ok(HttpClient::new(entry.get().clone())),
246246
Entry::Vacant(entry) => {
247247
let client = create_http_client(
248-
get_user_agent(),
248+
user_agent(),
249249
CreateHttpClientOptions {
250250
root_cert_store: match &self.root_cert_store_provider {
251251
Some(provider) => Some(provider.get_or_try_init()?.clone()),

deno/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub use deno_resolver;
7878
pub use node_resolver;
7979

8080
pub use deno_permissions::PermissionsContainer;
81+
pub use versions::edge_runtime_version;
8182

8283
pub fn version() -> &'static str {
8384
env!("CARGO_PKG_VERSION")

deno/versions.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
use std::borrow::Cow;
22

33
use deno_telemetry::OtelRuntimeConfig;
4+
use once_cell::sync::Lazy;
45

56
use crate::version;
67

7-
pub fn deno() -> &'static str {
8-
concat!("Supa:", "0")
8+
pub fn edge_runtime_version() -> &'static str {
9+
option_env!("GIT_V_TAG").unwrap_or("0.1.0")
910
}
1011

11-
pub fn get_user_agent() -> &'static str {
12-
concat!("Supa:", "0")
12+
pub fn user_agent() -> &'static str {
13+
static VALUE: Lazy<String> = Lazy::new(|| {
14+
let deno_version = version();
15+
let edge_runtime_version = edge_runtime_version();
16+
format!(
17+
// TODO: It should be changed to a well-known name for the ecosystem.
18+
"Deno/{} (variant; SupabaseEdgeRuntime/{})",
19+
deno_version, edge_runtime_version
20+
)
21+
});
22+
23+
VALUE.as_str()
1324
}
1425

1526
pub fn is_canary() -> bool {

0 commit comments

Comments
 (0)