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)]
|
||||
#[error("Cache deletion is not supported")]
|
||||
DeletionNotSupported,
|
||||
#[class(type)]
|
||||
#[error("Content-Encoding is not allowed in response headers")]
|
||||
ContentEncodingNotAllowed,
|
||||
#[class(generic)]
|
||||
#[error(transparent)]
|
||||
Sqlite(#[from] rusqlite::Error),
|
||||
|
@ -68,6 +71,15 @@ pub enum CacheError {
|
|||
#[source]
|
||||
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)]
|
||||
|
|
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.
|
||||
|
||||
use anyhow::Context;
|
||||
use hyper::header::AUTHORIZATION;
|
||||
use hyper::HeaderMap;
|
||||
use hyper::StatusCode;
|
||||
|
||||
use crate::CacheError;
|
||||
|
||||
pub struct CacheShard {
|
||||
client: reqwest::Client,
|
||||
endpoint: String,
|
||||
|
@ -26,7 +27,7 @@ impl CacheShard {
|
|||
pub async fn get_object(
|
||||
&self,
|
||||
object_key: &str,
|
||||
) -> anyhow::Result<Option<reqwest::Response>> {
|
||||
) -> Result<Option<reqwest::Response>, CacheError> {
|
||||
let res = self
|
||||
.client
|
||||
.get(format!("{}/objects/{}", self.endpoint, object_key))
|
||||
|
@ -34,18 +35,17 @@ impl CacheShard {
|
|||
.header("x-ryw", "1")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.without_url())
|
||||
.with_context(|| "failed to start cache GET request")?;
|
||||
.map_err(|e| e.without_url())?;
|
||||
|
||||
if res.status().is_success() {
|
||||
Ok(Some(res))
|
||||
} else if res.status() == StatusCode::NOT_FOUND {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"cache GET request failed: {}",
|
||||
res.status()
|
||||
))
|
||||
Err(CacheError::RequestFailed {
|
||||
method: "GET",
|
||||
status: res.status(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl CacheShard {
|
|||
object_key: &str,
|
||||
headers: HeaderMap,
|
||||
body: reqwest::Body,
|
||||
) -> anyhow::Result<()> {
|
||||
) -> Result<(), CacheError> {
|
||||
let res = self
|
||||
.client
|
||||
.put(format!("{}/objects/{}", self.endpoint, object_key))
|
||||
|
@ -63,16 +63,15 @@ impl CacheShard {
|
|||
.body(body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.without_url())
|
||||
.with_context(|| "failed to start cache PUT request")?;
|
||||
.map_err(|e| e.without_url())?;
|
||||
|
||||
if res.status().is_success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"cache PUT request failed: {}",
|
||||
res.status()
|
||||
))
|
||||
Err(CacheError::RequestFailed {
|
||||
method: "GET",
|
||||
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-";
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct LscBackend {
|
||||
shard: Rc<RefCell<Option<Rc<CacheShard>>>>,
|
||||
id2name: Rc<RefCell<Slab<String>>>,
|
||||
}
|
||||
|
||||
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>) {
|
||||
*self.shard.borrow_mut() = Some(shard);
|
||||
}
|
||||
|
@ -121,9 +114,7 @@ impl Cache for LscBackend {
|
|||
continue;
|
||||
}
|
||||
if hdr.0[..] == b"content-encoding"[..] {
|
||||
return Err(type_error(
|
||||
"Content-Encoding is not allowed in response headers",
|
||||
));
|
||||
return Err(CacheError::ContentEncodingNotAllowed);
|
||||
}
|
||||
headers.insert(
|
||||
HeaderName::from_bytes(&hdr.0[..])?,
|
||||
|
|
Loading…
Add table
Reference in a new issue