Skip to content

Commit

Permalink
Reorder imports and improve code formatting.
Browse files Browse the repository at this point in the history
Adjusted module imports across several files for consistent ordering.
  • Loading branch information
friedemannsommer committed Feb 22, 2025
1 parent d85ef4b commit 40e0f32
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/server/lib/fetch_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use actix_web::http::header::HeaderValue;
use crate::{
server::lib::get_content_security_policy,
utilities::{
fetch_validate_url, ClientRedirect, ClientResponse, ClientResponseBody, FetchResult,
FormRequest,
ClientRedirect, ClientResponse, ClientResponseBody, FetchResult, FormRequest,
fetch_validate_url,
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use content_security_policy::get_content_security_policy;
pub use error_response::{get_error_response, ErrorMessage};
pub use error_response::{ErrorMessage, get_error_response};
pub use fetch_url::fetch_url;

mod content_security_policy;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::templates::base::{blank_ref, Base};
use crate::templates::base::{Base, blank_ref};

pub fn error<'error_detail>(
error_detail_opt: &'error_detail Option<crate::server::lib::ErrorMessage<'_, '_>>,
Expand Down
4 changes: 2 additions & 2 deletions src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::templates::base::Base;

pub fn index(
) -> Base<impl std::fmt::Display + markup::Render, impl std::fmt::Display + markup::Render> {
pub fn index()
-> Base<impl std::fmt::Display + markup::Render, impl std::fmt::Display + markup::Render> {
Base {
header: markup::new! {
h2 {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/redirect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::templates::base::{self_ref, Base};
use crate::templates::base::{Base, self_ref};

pub fn redirect(
client_redirect: crate::utilities::ClientRedirect,
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use futures_util::StreamExt;
use crate::{
model::PermittedIpRange,
utilities::{
GLOBAL_CONFIG,
rewrite_css::{CssRewrite, RewriteCssError},
rewrite_html::HtmlRewrite,
rewrite_html::HtmlRewriteResult,
rewrite_url::rewrite_url,
GLOBAL_CONFIG,
},
};

Expand Down
8 changes: 4 additions & 4 deletions src/utilities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub use client::{
fetch_validate_url, BodyType, ClientError, ClientRedirect, ClientResponse, ClientResponseBody,
FetchResult, FormRequest,
BodyType, ClientError, ClientRedirect, ClientResponse, ClientResponseBody, FetchResult,
FormRequest, fetch_validate_url,
};
#[cfg(test)]
pub use shared::test_setup_hmac;
pub use shared::{
HmacInstance, BASE64_ENGINE, GLOBAL_CONFIG, HEADER_VALUE_CONTENT_HTML, HEADER_VALUE_NO_CACHE,
HMAC, REQUEST_CLIENT,
BASE64_ENGINE, GLOBAL_CONFIG, HEADER_VALUE_CONTENT_HTML, HEADER_VALUE_NO_CACHE, HMAC,
HmacInstance, REQUEST_CLIENT,
};

mod client;
Expand Down
32 changes: 25 additions & 7 deletions src/utilities/rewrite_css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::rc::Rc;

use url::Url;

use crate::utilities::rewrite_url::{rewrite_url, RewriteUrlError};
use crate::utilities::rewrite_url::{RewriteUrlError, rewrite_url};

#[derive(thiserror::Error, Debug)]
pub enum RewriteCssError {
Expand Down Expand Up @@ -243,7 +243,10 @@ mod tests {

rewriter.write(b"url(main.css)").unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(),"url(./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3)");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url(./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3)"
);
}

#[test]
Expand All @@ -255,7 +258,10 @@ mod tests {

rewriter.write(b"url('main.css')").unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(),"url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')"
);
}

#[test]
Expand All @@ -267,7 +273,10 @@ mod tests {

rewriter.write(b"url(\"main.css\")").unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(),"url(\"./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3\")");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url(\"./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3\")"
);
}

#[test]
Expand Down Expand Up @@ -344,7 +353,10 @@ mod tests {
.write(b"url('https://www.example.com/main.css')")
.unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(), "url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')"
);
}

#[test]
Expand Down Expand Up @@ -379,7 +391,10 @@ mod tests {
.write(b"url(\"https://www.example.com/main.css\")")
.unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(), "url(\"./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3\")");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url(\"./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3\")"
);
}

#[test]
Expand Down Expand Up @@ -412,6 +427,9 @@ mod tests {
.write(b"url(https://www.example.com/main.css)")
.unwrap();

assert_eq!(std::str::from_utf8( rewriter.end().unwrap().as_slice()).unwrap(), "url(./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3)");
assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().as_slice()).unwrap(),
"url(./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3)"
);
}
}
16 changes: 11 additions & 5 deletions src/utilities/rewrite_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl<'html> HtmlRewrite<'html> {
mod tests {
use std::rc::Rc;

use crate::utilities::rewrite_html::{HtmlRewrite, HEADER_STYLE_ELEMENT};
use crate::utilities::rewrite_html::{HEADER_STYLE_ELEMENT, HtmlRewrite};

#[test]
fn rewrite_a_href_relative_n_1() {
Expand Down Expand Up @@ -916,9 +916,12 @@ mod tests {

assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().html.as_slice()).unwrap(),
format!("<head><style>\
format!(
"<head><style>\
body{{background-image:url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')}}\
</style>{}</head>",HEADER_STYLE_ELEMENT.as_str())
</style>{}</head>",
HEADER_STYLE_ELEMENT.as_str()
)
);
}

Expand All @@ -936,10 +939,13 @@ mod tests {

assert_eq!(
std::str::from_utf8(rewriter.end().unwrap().html.as_slice()).unwrap(),
format!("<head><style>url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')</style>\
format!(
"<head><style>url('./?url=https%3A%2F%2Fwww.example.com%2Fmain.css&hash=7d40cd69599262cfe009ac148491a37e9ec47dcf2386c2807bc2255fff6d5fa3')</style>\
<style>url('./?url=https%3A%2F%2Fwww.example.com%2Findex.css&hash=de26b17e7788f85987457601375a920242dee16379bd17769fe6b6fbcb90cfcf')</style>\
<style>url('./?url=https%3A%2F%2Fwww.example.com%2Ftheme.css&hash=ddc8ae45cdbef1f3ddfc778ba578b36666f3b2541de07d5efbc1a2584a3e913c')</style>\
{}</head>",HEADER_STYLE_ELEMENT.as_str())
{}</head>",
HEADER_STYLE_ELEMENT.as_str()
)
);
}

Expand Down
33 changes: 25 additions & 8 deletions src/utilities/rewrite_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ mod tests {
crate::utilities::test_setup_hmac();

assert_eq!(
rewrite_url(&url::Url::parse("https://www.example.com").unwrap(), "/index.html")
.unwrap(),
rewrite_url(
&url::Url::parse("https://www.example.com").unwrap(),
"/index.html"
)
.unwrap(),
"./?url=https%3A%2F%2Fwww.example.com%2Findex.html&hash=7554946c4d3998da8be40b803c938c943f3dbbbb78958addd008b55bcacfb8c0"
);
}
Expand All @@ -82,8 +85,11 @@ mod tests {
crate::utilities::test_setup_hmac();

assert_eq!(
rewrite_url(&url::Url::parse("https://www.example.com/home/about").unwrap(), "../index.html")
.unwrap(),
rewrite_url(
&url::Url::parse("https://www.example.com/home/about").unwrap(),
"../index.html"
)
.unwrap(),
"./?url=https%3A%2F%2Fwww.example.com%2Findex.html&hash=7554946c4d3998da8be40b803c938c943f3dbbbb78958addd008b55bcacfb8c0"
);
}
Expand All @@ -93,8 +99,11 @@ mod tests {
crate::utilities::test_setup_hmac();

assert_eq!(
rewrite_url(&url::Url::parse("https://example.com/").unwrap(), "https://www.example.com/")
.unwrap(),
rewrite_url(
&url::Url::parse("https://example.com/").unwrap(),
"https://www.example.com/"
)
.unwrap(),
"./?url=https%3A%2F%2Fwww.example.com%2F&hash=85870232cac1676c4477f7cae4da7173ccee4002f32e89c16038547aa20175c0"
);
}
Expand Down Expand Up @@ -170,7 +179,11 @@ mod tests {
crate::utilities::test_setup_hmac();

assert_eq!(
rewrite_url(&url::Url::parse("https://example.com/").unwrap(), "/home/#about").unwrap(),
rewrite_url(
&url::Url::parse("https://example.com/").unwrap(),
"/home/#about"
)
.unwrap(),
"./?url=https%3A%2F%2Fexample.com%2Fhome%2F&hash=3af87c981235827014507736715a403ebd2f9c875689318184ba2cc035ea3e61#about"
);
}
Expand All @@ -180,7 +193,11 @@ mod tests {
crate::utilities::test_setup_hmac();

assert_eq!(
rewrite_url(&url::Url::parse("https://example.com/").unwrap(), "https://another.example.com/#about").unwrap(),
rewrite_url(
&url::Url::parse("https://example.com/").unwrap(),
"https://another.example.com/#about"
)
.unwrap(),
"./?url=https%3A%2F%2Fanother.example.com%2F&hash=743bb69ce433c306c9883528f2a7b451531362a1d41bbf6519ed97cdb81b907b#about"
);
}
Expand Down

0 comments on commit 40e0f32

Please sign in to comment.