Skip to content

Commit a62be7e

Browse files
committed
chore: update dependencies
1 parent 042bed7 commit a62be7e

File tree

5 files changed

+74
-57
lines changed

5 files changed

+74
-57
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ once_cell = "1"
5050
open = "5"
5151
oxipng = "9"
5252
parking_lot = "0.12"
53-
rand = "0.8.5"
53+
rand = "0.9.0"
5454
remove_dir_all = "1"
5555
reqwest = { version = "0.12", default-features = false, features = ["stream", "trust-dns"] }
5656
schemars = { version = "0.8", features = ["derive"] }
@@ -60,7 +60,7 @@ serde = { version = "1", features = ["derive"] }
6060
serde_json = "1"
6161
serde_yaml = "=0.9.33" # serde-yaml is deprecated, but "just works", let's see who becomes the next serde_yaml
6262
sha2 = "0.10"
63-
strum = { version = "0.26", features = ["derive"] }
63+
strum = { version = "0.27.1", features = ["derive"] }
6464
tar = "0.4"
6565
thiserror = "2"
6666
time = { version = "0.3", features = ["serde-well-known"] }
@@ -89,7 +89,7 @@ nu-ansi-term = "0.46"
8989

9090
[dev-dependencies]
9191
tempfile = "3"
92-
rstest = "0.24"
92+
rstest = "0.25.0"
9393

9494
[features]
9595
default = ["update_check", "rustls"]

src/common/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ use anyhow::{anyhow, bail, Context, Result};
55
use base64::{engine::general_purpose, Engine};
66
use console::Emoji;
77
use once_cell::sync::Lazy;
8-
use rand::RngCore;
9-
use std::collections::HashSet;
10-
use std::ffi::OsStr;
11-
use std::fmt::Debug;
12-
use std::fs::Metadata;
13-
use std::io::ErrorKind;
14-
use std::path::{Component, Path, PathBuf};
15-
use std::process::Stdio;
16-
use tokio::fs;
17-
use tokio::process::Command;
8+
use rand::TryRngCore;
9+
use std::{
10+
collections::HashSet,
11+
ffi::OsStr,
12+
fmt::Debug,
13+
fs::Metadata,
14+
io::ErrorKind,
15+
path::{Component, Path, PathBuf},
16+
process::Stdio,
17+
};
18+
use tokio::{fs, process::Command};
1819

1920
pub static BUILDING: Emoji = Emoji("📦 ", "");
2021
pub static SUCCESS: Emoji = Emoji("✅ ", "");
@@ -276,10 +277,10 @@ pub fn path_to_href(path: impl AsRef<Path>) -> String {
276277
/// A nonce random generator for script and style
277278
///
278279
/// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
279-
pub fn nonce() -> String {
280+
pub fn nonce() -> anyhow::Result<String> {
280281
let mut buffer = [0u8; 16];
281-
rand::rngs::OsRng.fill_bytes(&mut buffer);
282-
general_purpose::STANDARD.encode(buffer)
282+
rand::rngs::OsRng.try_fill_bytes(&mut buffer)?;
283+
Ok(general_purpose::STANDARD.encode(buffer))
283284
}
284285

285286
/// Creates the 'nonce' attribute.

src/pipelines/tailwind_css_extra.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl TailwindCssExtraOutput {
190190
// Insert the inlined CSS into a `<style>` tag.
191191
CssExtraRef::Inline(css) => format!(
192192
r#"<style {attrs} nonce="{}">{css}</style>"#,
193-
nonce(),
193+
nonce()?,
194194
attrs = AttrWriter::new(&self.attrs, AttrWriter::EXCLUDE_CSS_INLINE)
195195
),
196196
// Link to the CSS file.

src/serve/mod.rs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
11
mod proxy;
22

3-
use crate::common::{nonce, LOCAL, NETWORK, SERVER};
4-
use crate::config::rt::RtcServe;
5-
use crate::tls::TlsConfig;
6-
use crate::watch::WatchSystem;
7-
use crate::ws;
3+
use crate::{
4+
common::{nonce, LOCAL, NETWORK, SERVER},
5+
config::rt::RtcServe,
6+
tls::TlsConfig,
7+
watch::WatchSystem,
8+
ws,
9+
};
810
use anyhow::{Context, Result};
9-
use axum::body::{Body, Bytes};
10-
use axum::extract;
11-
use axum::extract::ws::WebSocketUpgrade;
12-
use axum::http::header::{HeaderName, CONTENT_LENGTH, CONTENT_TYPE, HOST};
13-
use axum::http::{HeaderValue, StatusCode};
14-
use axum::middleware::Next;
15-
use axum::response::{IntoResponse, Response};
16-
use axum::routing::{get, get_service, Router};
11+
use axum::{
12+
body::{Body, Bytes},
13+
extract::{self, ws::WebSocketUpgrade},
14+
http::{
15+
header::{HeaderName, CONTENT_LENGTH, CONTENT_TYPE, HOST},
16+
HeaderValue, StatusCode,
17+
},
18+
middleware::Next,
19+
response::{IntoResponse, Response},
20+
routing::{get, get_service, Router},
21+
};
1722
use axum_server::Handle;
1823
use futures_util::FutureExt;
1924
use hickory_resolver::TokioAsyncResolver;
20-
use http::header::CONTENT_SECURITY_POLICY;
21-
use http::HeaderMap;
25+
use http::{header::CONTENT_SECURITY_POLICY, HeaderMap};
2226
use proxy::{ProxyBuilder, ProxyClientOptions};
23-
use std::collections::{BTreeSet, HashMap, HashSet};
24-
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
25-
use std::path::PathBuf;
26-
use std::sync::Arc;
27-
use std::time::Duration;
28-
use tokio::select;
29-
use tokio::sync::{broadcast, watch};
30-
use tokio::task::JoinHandle;
31-
use tower_http::services::{ServeDir, ServeFile};
32-
use tower_http::set_header::SetResponseHeaderLayer;
33-
use tower_http::trace::TraceLayer;
27+
use std::{
28+
collections::{BTreeSet, HashMap, HashSet},
29+
net::{IpAddr, Ipv4Addr, SocketAddr},
30+
path::PathBuf,
31+
sync::Arc,
32+
time::Duration,
33+
};
34+
use tokio::{
35+
select,
36+
sync::{broadcast, watch},
37+
task::JoinHandle,
38+
};
39+
use tower_http::{
40+
services::{ServeDir, ServeFile},
41+
set_header::SetResponseHeaderLayer,
42+
trace::TraceLayer,
43+
};
3444
use tracing::log;
3545

3646
const INDEX_HTML: &str = "index.html";
@@ -486,11 +496,17 @@ async fn html_address_middleware(
486496
// split into parts and body
487497
let (parts, body) = response.into_parts();
488498

489-
let nonce = state
490-
.cfg
491-
.create_nonce
492-
.as_ref()
493-
.map(|p| (p.as_str(), nonce()));
499+
let nonce = match &state.cfg.create_nonce {
500+
Some(p) => match nonce() {
501+
Ok(nonce) => Some((p.as_str(), nonce)),
502+
Err(err) => {
503+
tracing::warn!("Failed to create nonce: {err}");
504+
return (StatusCode::INTERNAL_SERVER_ERROR, "Failed to create nonce")
505+
.into_response();
506+
}
507+
},
508+
None => None,
509+
};
494510

495511
// turn the body into bytes
496512
match axum::body::to_bytes(body, 100 * 1024 * 1024).await {

0 commit comments

Comments
 (0)