Skip to content
Closed
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
10 changes: 0 additions & 10 deletions src/runtime/server/RequestContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2561,22 +2561,12 @@ where
};
let credentials = s3.get_credentials();
let path = s3.path();
// `Transpiler::env_mut` is the safe accessor for the
// process-singleton dotenv loader (set during init).
let proxy_url = global_this
.bun_vm()
.as_mut()
.transpiler
.env_mut()
.get_http_proxy(true, None, None)
.map(|proxy| proxy.href);

let _ = S3::client::stat(
credentials,
path,
Self::on_s3_size_resolved_thunk,
this.as_ctx_ptr().cast::<c_void>(),
proxy_url,
s3.request_payer,
); // TODO: properly propagate exception upwards
return;
Expand Down
68 changes: 5 additions & 63 deletions src/runtime/webcore/Blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ use crate::webcore::{self, Lifetime, ReadableStream, Request, Response, streams}

bun_core::define_scoped_log!(debug, Blob, visible);

/// `bunVM().transpiler.env.getHttpProxy(true, null, null)?.href` as an owned
/// buffer. Owned (not borrowed) because the env loader's `URL<'_>` ties the
/// `href` slice to a `&mut Loader` borrow that we cannot keep open across the
/// S3 request setup.
#[inline]
fn http_proxy_href(global: &JSGlobalObject) -> Option<Vec<u8>> {
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (initialised before any JS runs).
global
.bun_vm()
.as_mut()
.transpiler
.env_mut()
.get_http_proxy(true, None, None)
.map(|p| p.href.to_vec())
}

#[path = "blob/Store.rs"]
pub mod store;
use crate::node::types::{PathLikeExt as _, PathOrFdExt as _};
Expand Down Expand Up @@ -617,7 +600,6 @@ impl BlobExt for Blob {
poll: bun_io::KeepAlive::default(),
});
t.poll.ref_(bun_io::js_vm_ctx());
let proxy = http_proxy_href(global);
// reshaped for borrowck — `heap::alloc(t)` moves `t`, so clone the
// credentials ref out and stash `path` as a raw `*const [u8]`
// whose backing store is kept alive by the same `t.blob` now
Expand Down Expand Up @@ -651,18 +633,10 @@ impl BlobExt for Blob {
len,
Task::<H>::cb,
t_ptr,
proxy.as_deref(),
payer,
)?;
} else {
crate::webcore::__s3_client::download(
&cred,
path,
Task::<H>::cb,
t_ptr,
proxy.as_deref(),
payer,
)?;
crate::webcore::__s3_client::download(&cred, path, Task::<H>::cb, t_ptr, payer)?;
}
return Ok(());
}
Expand Down Expand Up @@ -1396,12 +1370,6 @@ impl BlobExt for Blob {
};

let path = s3.path();
// SAFETY: bun_vm() never returns null for a Bun-owned global; `env`
// is a live `*mut Loader` owned by the transpiler.
let proxy = unsafe {
(*global_this.bun_vm().as_mut().transpiler.env).get_http_proxy(true, None, None)
};
let proxy_url = proxy.map(|p| p.href);

// When no JS overrides were supplied, hand the store's *base*
// credentials to the upload.
Expand All @@ -1422,7 +1390,7 @@ impl BlobExt for Blob {
// backing storage is owned by `aws_options` which outlives this call.
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
proxy_url,
None,
aws_options.request_payer,
None,
core::ptr::null_mut(),
Expand Down Expand Up @@ -1679,16 +1647,6 @@ impl BlobExt for Blob {
// content-type writes below don't conflict.
let s3 = store.data.as_s3();
let path = s3.path();
// SAFETY: `bun_vm()` returns the live per-global VM; `transpiler.env`
// is the process-singleton dotenv loader, never null once init'd.
let proxy_url: Option<bun_url::URL<'_>> = unsafe {
(*global_this.bun_vm().as_mut().transpiler.env).get_http_proxy(true, None, None)
};
// Copy the href out of the env map before any reentrant JS (the
// `get_truthy`/credential getters below) can mutate `process.env`
// and free the backing allocation.
let proxy_owned: Option<Vec<u8>> = proxy_url.as_ref().map(|p| p.href.to_vec());
let proxy = proxy_owned.as_deref();

if has_args && arg0.is_object() {
let options = arg0;
Expand Down Expand Up @@ -1735,7 +1693,6 @@ impl BlobExt for Blob {
self.content_type_or_mime_type(),
content_disposition_str.as_ref().map(|s| s.slice()),
content_encoding_str.as_ref().map(|s| s.slice()),
proxy,
credentials_with_options.storage_class,
credentials_with_options.request_payer,
);
Expand All @@ -1749,7 +1706,6 @@ impl BlobExt for Blob {
self.content_type_or_mime_type(),
None,
None,
proxy,
None,
s3.request_payer,
);
Expand Down Expand Up @@ -4392,8 +4348,6 @@ fn write_file_with_empty_source_to_destination(

let promise = jsc::JSPromiseStrong::init(ctx);
let promise_value = promise.value();
let proxy_owned = http_proxy_href(ctx);
let proxy_url = proxy_owned.as_deref();
s3_client::upload(
&aws_options.credentials,
s3.path(),
Expand All @@ -4402,7 +4356,6 @@ fn write_file_with_empty_source_to_destination(
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
aws_options.acl,
proxy_url,
aws_options.storage_class,
aws_options.request_payer,
Wrapper::resolve,
Expand Down Expand Up @@ -4575,8 +4528,6 @@ pub(crate) fn write_file_with_source_destination(
);
}
};
let proxy_owned = http_proxy_href(ctx);
let proxy_url = proxy_owned.as_deref();
match &source_store.data {
store::Data::Bytes(bytes) => {
if bytes.len() as usize > S3::MultiPartUploadOptions::MAX_SINGLE_UPLOAD_SIZE {
Expand All @@ -4603,7 +4554,7 @@ pub(crate) fn write_file_with_source_destination(
destination_blob.content_type_or_mime_type(),
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
proxy_url,
None,
aws_options.request_payer,
None,
core::ptr::null_mut(),
Expand Down Expand Up @@ -4660,7 +4611,6 @@ pub(crate) fn write_file_with_source_destination(
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
aws_options.acl,
proxy_url,
aws_options.storage_class,
aws_options.request_payer,
Wrapper::resolve,
Expand Down Expand Up @@ -4699,7 +4649,7 @@ pub(crate) fn write_file_with_source_destination(
destination_blob.content_type_or_mime_type(),
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
proxy_url,
None,
aws_options.request_payer,
None,
core::ptr::null_mut(),
Expand Down Expand Up @@ -4969,8 +4919,6 @@ pub(crate) fn write_file_internal(
"ReadableStream has already been used"
)));
}
let proxy_owned = http_proxy_href(global_this);
let proxy_url = proxy_owned.as_deref();
return Ok(ControlFlow::Break(s3_client::upload_stream(
if options.extra_options.is_some() {
aws_options.credentials.dupe()
Expand All @@ -4986,7 +4934,7 @@ pub(crate) fn write_file_internal(
destination_blob.content_type_or_mime_type(),
aws_options.content_disposition.as_deref(),
aws_options.content_encoding.as_deref(),
proxy_url,
None,
aws_options.request_payer,
None,
core::ptr::null_mut(),
Expand Down Expand Up @@ -5697,9 +5645,6 @@ impl S3BlobDownloadTask {
let credentials = s3_store.get_credentials();
let path = s3_store.path();

let proxy_owned = http_proxy_href(global_this);
let proxy = proxy_owned.as_deref();

fn s3_cb(
result: crate::webcore::__s3_client::S3DownloadResult<'_>,
ctx: *mut c_void,
Expand All @@ -5723,7 +5668,6 @@ impl S3BlobDownloadTask {
len,
s3_cb,
this.cast::<c_void>(),
proxy,
s3_store.request_payer,
)?;
} else if blob.size.get() == MAX_SIZE {
Expand All @@ -5732,7 +5676,6 @@ impl S3BlobDownloadTask {
path,
s3_cb,
this.cast::<c_void>(),
proxy,
s3_store.request_payer,
)?;
} else {
Expand All @@ -5745,7 +5688,6 @@ impl S3BlobDownloadTask {
Some(len),
s3_cb,
this.cast::<c_void>(),
proxy,
s3_store.request_payer,
)?;
}
Expand Down
10 changes: 0 additions & 10 deletions src/runtime/webcore/ReadableStream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,6 @@ impl ReadableStream {
webcore::blob::store::Data::S3(s3) => {
let credentials = s3.get_credentials();
let path = s3.path();
// `Transpiler::env_mut` is the safe accessor for the
// process-singleton dotenv loader (set during init).
let proxy = global_this
.bun_vm()
.as_mut()
.transpiler
.env_mut()
.get_http_proxy(true, None, None);
let proxy_url = proxy.as_ref().map(|p| p.href);

crate::webcore::s3::client::readable_stream(
credentials,
Expand All @@ -555,7 +546,6 @@ impl ReadableStream {
} else {
None
},
proxy_url,
s3.request_payer,
global_this,
)
Expand Down
12 changes: 0 additions & 12 deletions src/runtime/webcore/S3File.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,12 @@ impl S3BlobStatTask {
let s3_store = blob.store.get().as_ref().unwrap().data.as_s3();
let credentials = s3_store.get_credentials();
let path = s3_store.path();
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (set during init).
let env = global.bun_vm().as_mut().transpiler.env_mut();

s3::stat(
credentials,
path,
S3BlobStatTask::on_s3_exists_resolved,
this.cast::<core::ffi::c_void>(),
env.get_http_proxy(true, None, None).map(|proxy| proxy.href),
s3_store.request_payer,
)?;
Ok(promise)
Expand All @@ -498,16 +494,12 @@ impl S3BlobStatTask {
let s3_store = blob.store.get().as_ref().unwrap().data.as_s3();
let credentials = s3_store.get_credentials();
let path = s3_store.path();
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (set during init).
let env = global.bun_vm().as_mut().transpiler.env_mut();

s3::stat(
credentials,
path,
S3BlobStatTask::on_s3_stat_resolved,
this.cast::<core::ffi::c_void>(),
env.get_http_proxy(true, None, None).map(|proxy| proxy.href),
s3_store.request_payer,
)?;
Ok(promise)
Expand All @@ -525,16 +517,12 @@ impl S3BlobStatTask {
let s3_store = blob.store.get().as_ref().unwrap().data.as_s3();
let credentials = s3_store.get_credentials();
let path = s3_store.path();
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (set during init).
let env = global.bun_vm().as_mut().transpiler.env_mut();

s3::stat(
credentials,
path,
S3BlobStatTask::on_s3_size_resolved,
this.cast::<core::ffi::c_void>(),
env.get_http_proxy(true, None, None).map(|proxy| proxy.href),
s3_store.request_payer,
)?;
Ok(promise)
Expand Down
21 changes: 0 additions & 21 deletions src/runtime/webcore/blob/Store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::webcore::s3::client::{
use bun_core::strings;
use bun_http_types::MimeType::MimeType;
use bun_ptr::RefPtr;
use bun_url::URL;

#[cfg(unix)]
use super::SizeType;
Expand Down Expand Up @@ -314,15 +313,6 @@ impl S3Ext for S3 {

let promise = bun_jsc::JSPromiseStrong::init(global_this);
let value = promise.value();
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (never null once the VM is initialised).
let proxy_url: Option<URL<'_>> = global_this
.bun_vm()
.as_mut()
.transpiler
.env_mut()
.get_http_proxy(true, None, None);
let proxy = proxy_url.as_ref().map(|url| url.href);
let aws_options = self.get_credentials_with_options(extra_options, global_this)?;
// `defer aws_options.deinit()` → Drop handles it.

Expand All @@ -336,7 +326,6 @@ impl S3Ext for S3 {
global: bun_ptr::BackRef::new(global_this),
}))
.cast::<c_void>(),
proxy,
aws_options.request_payer,
)?;

Expand Down Expand Up @@ -400,15 +389,6 @@ impl S3Ext for S3 {

let promise = bun_jsc::JSPromiseStrong::init(global_this);
let value = promise.value();
// `Transpiler::env_mut` is the safe accessor for the process-singleton
// dotenv loader (never null once the VM is initialised).
let proxy_url: Option<URL<'_>> = global_this
.bun_vm()
.as_mut()
.transpiler
.env_mut()
.get_http_proxy(true, None, None);
let proxy = proxy_url.as_ref().map(|url| url.href);
let aws_options = self.get_credentials_with_options(extra_options, global_this)?;
// `defer aws_options.deinit()` → Drop handles it.

Expand All @@ -432,7 +412,6 @@ impl S3Ext for S3 {
unsafe { &(*wrapper).resolved_list_options },
Wrapper::resolve,
wrapper.cast::<c_void>(),
proxy,
)?;

Ok(value)
Expand Down
Loading
Loading