Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Mar 4, 2025
1 parent 042bed7 commit a62be7e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 57 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ once_cell = "1"
open = "5"
oxipng = "9"
parking_lot = "0.12"
rand = "0.8.5"
rand = "0.9.0"
remove_dir_all = "1"
reqwest = { version = "0.12", default-features = false, features = ["stream", "trust-dns"] }
schemars = { version = "0.8", features = ["derive"] }
Expand All @@ -60,7 +60,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_yaml = "=0.9.33" # serde-yaml is deprecated, but "just works", let's see who becomes the next serde_yaml
sha2 = "0.10"
strum = { version = "0.26", features = ["derive"] }
strum = { version = "0.27.1", features = ["derive"] }
tar = "0.4"
thiserror = "2"
time = { version = "0.3", features = ["serde-well-known"] }
Expand Down Expand Up @@ -89,7 +89,7 @@ nu-ansi-term = "0.46"

[dev-dependencies]
tempfile = "3"
rstest = "0.24"
rstest = "0.25.0"

[features]
default = ["update_check", "rustls"]
Expand Down
27 changes: 14 additions & 13 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use anyhow::{anyhow, bail, Context, Result};
use base64::{engine::general_purpose, Engine};
use console::Emoji;
use once_cell::sync::Lazy;
use rand::RngCore;
use std::collections::HashSet;
use std::ffi::OsStr;
use std::fmt::Debug;
use std::fs::Metadata;
use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf};
use std::process::Stdio;
use tokio::fs;
use tokio::process::Command;
use rand::TryRngCore;
use std::{
collections::HashSet,
ffi::OsStr,
fmt::Debug,
fs::Metadata,
io::ErrorKind,
path::{Component, Path, PathBuf},
process::Stdio,
};
use tokio::{fs, process::Command};

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

/// Creates the 'nonce' attribute.
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/tailwind_css_extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl TailwindCssExtraOutput {
// Insert the inlined CSS into a `<style>` tag.
CssExtraRef::Inline(css) => format!(
r#"<style {attrs} nonce="{}">{css}</style>"#,
nonce(),
nonce()?,
attrs = AttrWriter::new(&self.attrs, AttrWriter::EXCLUDE_CSS_INLINE)
),
// Link to the CSS file.
Expand Down
78 changes: 47 additions & 31 deletions src/serve/mod.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
mod proxy;

use crate::common::{nonce, LOCAL, NETWORK, SERVER};
use crate::config::rt::RtcServe;
use crate::tls::TlsConfig;
use crate::watch::WatchSystem;
use crate::ws;
use crate::{
common::{nonce, LOCAL, NETWORK, SERVER},
config::rt::RtcServe,
tls::TlsConfig,
watch::WatchSystem,
ws,
};
use anyhow::{Context, Result};
use axum::body::{Body, Bytes};
use axum::extract;
use axum::extract::ws::WebSocketUpgrade;
use axum::http::header::{HeaderName, CONTENT_LENGTH, CONTENT_TYPE, HOST};
use axum::http::{HeaderValue, StatusCode};
use axum::middleware::Next;
use axum::response::{IntoResponse, Response};
use axum::routing::{get, get_service, Router};
use axum::{
body::{Body, Bytes},
extract::{self, ws::WebSocketUpgrade},
http::{
header::{HeaderName, CONTENT_LENGTH, CONTENT_TYPE, HOST},
HeaderValue, StatusCode,
},
middleware::Next,
response::{IntoResponse, Response},
routing::{get, get_service, Router},
};
use axum_server::Handle;
use futures_util::FutureExt;
use hickory_resolver::TokioAsyncResolver;
use http::header::CONTENT_SECURITY_POLICY;
use http::HeaderMap;
use http::{header::CONTENT_SECURITY_POLICY, HeaderMap};
use proxy::{ProxyBuilder, ProxyClientOptions};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tokio::select;
use tokio::sync::{broadcast, watch};
use tokio::task::JoinHandle;
use tower_http::services::{ServeDir, ServeFile};
use tower_http::set_header::SetResponseHeaderLayer;
use tower_http::trace::TraceLayer;
use std::{
collections::{BTreeSet, HashMap, HashSet},
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
sync::Arc,
time::Duration,
};
use tokio::{
select,
sync::{broadcast, watch},
task::JoinHandle,
};
use tower_http::{
services::{ServeDir, ServeFile},
set_header::SetResponseHeaderLayer,
trace::TraceLayer,
};
use tracing::log;

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

let nonce = state
.cfg
.create_nonce
.as_ref()
.map(|p| (p.as_str(), nonce()));
let nonce = match &state.cfg.create_nonce {
Some(p) => match nonce() {
Ok(nonce) => Some((p.as_str(), nonce)),
Err(err) => {
tracing::warn!("Failed to create nonce: {err}");
return (StatusCode::INTERNAL_SERVER_ERROR, "Failed to create nonce")
.into_response();
}
},
None => None,
};

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

0 comments on commit a62be7e

Please sign in to comment.