mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
lints now
This commit is contained in:
parent
0df9a78956
commit
1415c99606
3 changed files with 28 additions and 26 deletions
12
ext/cache/lib.rs
vendored
12
ext/cache/lib.rs
vendored
|
@ -40,6 +40,9 @@ pub enum CacheError {
|
||||||
#[class(type)]
|
#[class(type)]
|
||||||
#[error("Cache deletion is not supported")]
|
#[error("Cache deletion is not supported")]
|
||||||
DeletionNotSupported,
|
DeletionNotSupported,
|
||||||
|
#[class(type)]
|
||||||
|
#[error("Content-Encoding is not allowed in response headers")]
|
||||||
|
ContentEncodingNotAllowed,
|
||||||
#[class(generic)]
|
#[class(generic)]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Sqlite(#[from] rusqlite::Error),
|
Sqlite(#[from] rusqlite::Error),
|
||||||
|
@ -68,6 +71,15 @@ pub enum CacheError {
|
||||||
#[source]
|
#[source]
|
||||||
source: std::io::Error,
|
source: std::io::Error,
|
||||||
},
|
},
|
||||||
|
#[class(generic)]
|
||||||
|
#[error("cache {method} request failed: {status}")]
|
||||||
|
RequestFailed {
|
||||||
|
method: &'static str,
|
||||||
|
status: hyper::StatusCode,
|
||||||
|
},
|
||||||
|
#[class(generic)]
|
||||||
|
#[error("{0}")]
|
||||||
|
Reqwest(#[from] reqwest::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
29
ext/cache/lsc_shard.rs
vendored
29
ext/cache/lsc_shard.rs
vendored
|
@ -1,10 +1,11 @@
|
||||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use hyper::header::AUTHORIZATION;
|
use hyper::header::AUTHORIZATION;
|
||||||
use hyper::HeaderMap;
|
use hyper::HeaderMap;
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
|
|
||||||
|
use crate::CacheError;
|
||||||
|
|
||||||
pub struct CacheShard {
|
pub struct CacheShard {
|
||||||
client: reqwest::Client,
|
client: reqwest::Client,
|
||||||
endpoint: String,
|
endpoint: String,
|
||||||
|
@ -26,7 +27,7 @@ impl CacheShard {
|
||||||
pub async fn get_object(
|
pub async fn get_object(
|
||||||
&self,
|
&self,
|
||||||
object_key: &str,
|
object_key: &str,
|
||||||
) -> anyhow::Result<Option<reqwest::Response>> {
|
) -> Result<Option<reqwest::Response>, CacheError> {
|
||||||
let res = self
|
let res = self
|
||||||
.client
|
.client
|
||||||
.get(format!("{}/objects/{}", self.endpoint, object_key))
|
.get(format!("{}/objects/{}", self.endpoint, object_key))
|
||||||
|
@ -34,18 +35,17 @@ impl CacheShard {
|
||||||
.header("x-ryw", "1")
|
.header("x-ryw", "1")
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.without_url())
|
.map_err(|e| e.without_url())?;
|
||||||
.with_context(|| "failed to start cache GET request")?;
|
|
||||||
|
|
||||||
if res.status().is_success() {
|
if res.status().is_success() {
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
} else if res.status() == StatusCode::NOT_FOUND {
|
} else if res.status() == StatusCode::NOT_FOUND {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow::anyhow!(
|
Err(CacheError::RequestFailed {
|
||||||
"cache GET request failed: {}",
|
method: "GET",
|
||||||
res.status()
|
status: res.status(),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ impl CacheShard {
|
||||||
object_key: &str,
|
object_key: &str,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
body: reqwest::Body,
|
body: reqwest::Body,
|
||||||
) -> anyhow::Result<()> {
|
) -> Result<(), CacheError> {
|
||||||
let res = self
|
let res = self
|
||||||
.client
|
.client
|
||||||
.put(format!("{}/objects/{}", self.endpoint, object_key))
|
.put(format!("{}/objects/{}", self.endpoint, object_key))
|
||||||
|
@ -63,16 +63,15 @@ impl CacheShard {
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.without_url())
|
.map_err(|e| e.without_url())?;
|
||||||
.with_context(|| "failed to start cache PUT request")?;
|
|
||||||
|
|
||||||
if res.status().is_success() {
|
if res.status().is_success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow::anyhow!(
|
Err(CacheError::RequestFailed {
|
||||||
"cache PUT request failed: {}",
|
method: "GET",
|
||||||
res.status()
|
status: res.status(),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
ext/cache/lscache.rs
vendored
13
ext/cache/lscache.rs
vendored
|
@ -39,20 +39,13 @@ use crate::CachePutRequest;
|
||||||
|
|
||||||
const REQHDR_PREFIX: &str = "x-lsc-meta-reqhdr-";
|
const REQHDR_PREFIX: &str = "x-lsc-meta-reqhdr-";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct LscBackend {
|
pub struct LscBackend {
|
||||||
shard: Rc<RefCell<Option<Rc<CacheShard>>>>,
|
shard: Rc<RefCell<Option<Rc<CacheShard>>>>,
|
||||||
id2name: Rc<RefCell<Slab<String>>>,
|
id2name: Rc<RefCell<Slab<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LscBackend {
|
impl LscBackend {
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
shard: Rc::new(RefCell::new(None)),
|
|
||||||
id2name: Rc::new(RefCell::new(Slab::new())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_shard(&self, shard: Rc<CacheShard>) {
|
pub fn set_shard(&self, shard: Rc<CacheShard>) {
|
||||||
*self.shard.borrow_mut() = Some(shard);
|
*self.shard.borrow_mut() = Some(shard);
|
||||||
}
|
}
|
||||||
|
@ -121,9 +114,7 @@ impl Cache for LscBackend {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if hdr.0[..] == b"content-encoding"[..] {
|
if hdr.0[..] == b"content-encoding"[..] {
|
||||||
return Err(type_error(
|
return Err(CacheError::ContentEncodingNotAllowed);
|
||||||
"Content-Encoding is not allowed in response headers",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
headers.insert(
|
headers.insert(
|
||||||
HeaderName::from_bytes(&hdr.0[..])?,
|
HeaderName::from_bytes(&hdr.0[..])?,
|
||||||
|
|
Loading…
Add table
Reference in a new issue