mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
cleanup
This commit is contained in:
parent
97a9369dd6
commit
6805f0d2d4
1 changed files with 5 additions and 13 deletions
|
@ -63,6 +63,7 @@ pub struct Options {
|
||||||
pub root_cert_store: Option<RootCertStore>,
|
pub root_cert_store: Option<RootCertStore>,
|
||||||
pub proxy: Option<Proxy>,
|
pub proxy: Option<Proxy>,
|
||||||
pub request_builder_hook: Option<fn(RequestBuilder) -> RequestBuilder>,
|
pub request_builder_hook: Option<fn(RequestBuilder) -> RequestBuilder>,
|
||||||
|
/// Called on every request. Defaults to process-wide shared client.
|
||||||
pub get_client: Option<fn(&mut OpState) -> Client>,
|
pub get_client: Option<fn(&mut OpState) -> Client>,
|
||||||
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
pub client_cert_chain_and_key: Option<(String, String)>,
|
pub client_cert_chain_and_key: Option<(String, String)>,
|
||||||
|
@ -120,7 +121,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assign to Options::get_client for a fetch that creates a new client for every request.
|
/// Assign to Options::get_client for a fetch that creates a new client for every request.
|
||||||
pub fn get_new_client(state: &mut OpState) -> Client {
|
pub fn new_client(state: &mut OpState) -> Client {
|
||||||
let options = state.borrow::<Options>();
|
let options = state.borrow::<Options>();
|
||||||
create_http_client(
|
create_http_client(
|
||||||
options.user_agent.clone(),
|
options.user_agent.clone(),
|
||||||
|
@ -133,20 +134,12 @@ pub fn get_new_client(state: &mut OpState) -> Client {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Default behavior when Options::get_client is None.
|
||||||
fn get_shared_client(state: &mut OpState) -> Client {
|
fn get_shared_client(state: &mut OpState) -> Client {
|
||||||
if let Some(client) = state.try_borrow::<Client>() {
|
if let Some(client) = state.try_borrow::<Client>() {
|
||||||
client.clone()
|
client.clone()
|
||||||
} else {
|
} else {
|
||||||
let options = state.borrow::<Options>();
|
let client = new_client(state);
|
||||||
let client = create_http_client(
|
|
||||||
options.user_agent.clone(),
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
vec![],
|
|
||||||
options.proxy.clone(),
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
options.client_cert_chain_and_key.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
state.put::<Client>(client.clone());
|
state.put::<Client>(client.clone());
|
||||||
client
|
client
|
||||||
}
|
}
|
||||||
|
@ -234,8 +227,7 @@ where
|
||||||
r.client.clone()
|
r.client.clone()
|
||||||
} else {
|
} else {
|
||||||
let options = state.borrow::<Options>();
|
let options = state.borrow::<Options>();
|
||||||
let client = options.get_client.unwrap()(state);
|
options.get_client.unwrap()(state)
|
||||||
client
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let method = Method::from_bytes(&args.method)?;
|
let method = Method::from_bytes(&args.method)?;
|
||||||
|
|
Loading…
Reference in a new issue