Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories = ["web-programming::http-server", "command-line-utilities"]
keywords = ["web", "server", "http", "templating", "handlebars"]
readme = "README.md"
license = "GPL-3.0"
edition = "2021"
edition = "2024"
include = [
"src/**/*",
"Cargo.toml",
Expand Down
4 changes: 2 additions & 2 deletions benches/load_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use actix_web::error::PayloadError;
use actix_web::http::StatusCode;
use actix_web::test::unused_addr;
use bytes::{Bytes, BytesMut};
use criterion::{criterion_main, BenchmarkId, Criterion};
use criterion::{BenchmarkId, Criterion, criterion_main};
use futures::FutureExt;
use futures::{future, Stream, TryStreamExt};
use futures::{Stream, TryStreamExt, future};
use lazy_static::lazy_static;
use mime_guess::MimeGuess;
use operator::content::ContentDirectory;
Expand Down
32 changes: 10 additions & 22 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,9 @@ mod tests {
);
let output_as_str = str::from_utf8(output.as_slice()).expect("Output was not UTF-8");
assert_eq!(
output_as_str,
expected_output,
output_as_str, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
output_as_str
template, expected_output, output_as_str
);
}
}
Expand Down Expand Up @@ -303,13 +300,10 @@ mod tests {
);
let output_as_str = str::from_utf8(output.as_slice()).expect("Output was not UTF-8");
assert_eq!(
output_as_str,
expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
output_as_str
);
output_as_str, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template, expected_output, output_as_str
);
}

#[test]
Expand All @@ -329,12 +323,9 @@ mod tests {
);
let output_as_str = str::from_utf8(output.as_slice()).expect("Output was not UTF-8");
assert_eq!(
output_as_str,
expected_output,
output_as_str, expected_output,
"Template rendering for content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route,
expected_output,
output_as_str
route, expected_output, output_as_str
);
}

Expand All @@ -355,12 +346,9 @@ mod tests {
);
let output_as_str = str::from_utf8(output.as_slice()).expect("Output was not UTF-8");
assert_eq!(
output_as_str,
expected_output,
output_as_str, expected_output,
"Template rendering for content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route,
expected_output,
output_as_str
route, expected_output, output_as_str
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use super::StreamError;
use crate::bug_message;
use bytes::Bytes;
use futures::future::{Future, FutureExt, LocalBoxFuture};
use futures::Stream;
use futures::future::{Future, FutureExt, LocalBoxFuture};
use std::cmp;
use std::fs::File;
use std::io::ErrorKind::Interrupted;
Expand Down
2 changes: 1 addition & 1 deletion src/content/content_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ContentFile {
return Err(ContentFileError(format!(
"Non-unicode directory root (path is similar to '{}')",
content_directory_root.display(),
)))
)));
}
};

Expand Down
88 changes: 28 additions & 60 deletions src/content/content_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use super::*;
use crate::bug_message;
use handlebars::{self, Handlebars};
use mime_guess::MimeGuess;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::path::Path;
use std::sync::{Arc, RwLock};
use thiserror::Error;
Expand Down Expand Up @@ -149,13 +149,13 @@ where
return Err(ContentLoadingError::ContentFileNameError(format!(
"Content file name '{}' has too many extensions.",
entry.relative_path
)))
)));
}
[] => {
return Err(ContentLoadingError::ContentFileNameError(format!(
"Content file names must have extensions, but '{}' does not.",
entry.relative_path
)))
)));
}
}
}
Expand Down Expand Up @@ -222,14 +222,12 @@ where
// have the executable bit set. They are evaluated when rendered.
[first_extension, Self::HANDLEBARS_FILE_EXTENSION] => {
if content.is_executable {
return Err(ContentLoadingError::ContentFileNameError(
format!(
"The content file '{}' appears to be a handlebars file (because it ends in '.{}'), \
return Err(ContentLoadingError::ContentFileNameError(format!(
"The content file '{}' appears to be a handlebars file (because it ends in '.{}'), \
but it is also executable. It must be one or the other.",
content.relative_path,
Self::HANDLEBARS_FILE_EXTENSION,
),
));
content.relative_path,
Self::HANDLEBARS_FILE_EXTENSION,
)));
}

let mime = MimeGuess::from_ext(first_extension)
Expand Down Expand Up @@ -480,12 +478,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
actual_output,
template, expected_output, actual_output,
);
}
}
Expand Down Expand Up @@ -539,12 +534,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
actual_output,
template, expected_output, actual_output,
);
}

Expand Down Expand Up @@ -573,12 +565,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Rendering content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route,
expected_output,
actual_output,
route, expected_output, actual_output,
);
}

Expand Down Expand Up @@ -639,12 +628,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
actual_output,
template, expected_output, actual_output,
);
}

Expand Down Expand Up @@ -709,12 +695,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
actual_output,
template, expected_output, actual_output,
);
}

Expand Down Expand Up @@ -750,12 +733,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Template rendering for `{}` did not produce the expected output (\"{}\"), instead got \"{}\"",
template,
expected_output,
actual_output,
template, expected_output, actual_output,
);
}

Expand Down Expand Up @@ -949,12 +929,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Rendering content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route,
expected_output,
actual_output,
route, expected_output, actual_output,
);
}

Expand All @@ -980,12 +957,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output1,
actual_output, expected_output1,
"Rendering content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route1,
expected_output1,
actual_output,
route1, expected_output1, actual_output,
);

let route2 = route("/subdirectory/pwd");
Expand All @@ -1003,12 +977,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output2,
actual_output, expected_output2,
"Rendering content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route2,
expected_output2,
actual_output,
route2, expected_output2, actual_output,
);
}

Expand Down Expand Up @@ -1099,12 +1070,9 @@ mod tests {
let actual_output = media_to_string(rendered);

assert_eq!(
actual_output,
expected_output,
actual_output, expected_output,
"Rendering content at '{}' did not produce the expected output (\"{}\"), instead got \"{}\"",
route,
expected_output,
actual_output,
route, expected_output, actual_output,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/content_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ContentIndexEntries {
failed_route: route.clone(),
message: format!(
"There is already a resource at '{conficting_route}', but that needs to be a directory to accommodate the new route.",
)
),
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/content/content_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ impl Executable {
mod tests {
use super::super::test_lib::*;
use super::*;
use crate::ServerInfo;
use crate::content::content_index::ContentIndexEntries;
use crate::test_lib::*;
use crate::ServerInfo;
use ::mime;
use maplit::hashmap;
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion src/content/content_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Render for ContentRepresentations {
)))
} else {
Ok(rendered)
}
};
}
Err(error) => {
log::warn!("Rendering failure: {error}");
Expand Down
12 changes: 8 additions & 4 deletions src/content/handlebars_helpers/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ where
let modified_context_data_as_json =
mem::take(Rc::make_mut(modified_context).data_mut());
match modified_context_data_as_json {
serde_json::Value::Object(modified_context_data_as_json_map) => modified_context_data_as_json_map,
serde_json::Value::Object(modified_context_data_as_json_map) => {
modified_context_data_as_json_map
}
_ => {
return Err(handlebars::RenderError::from(handlebars::RenderErrorReason::Other(format!(
"The `get \"{route}\"` helper call failed because the pre-existing handlebars render context \
return Err(handlebars::RenderError::from(
handlebars::RenderErrorReason::Other(format!(
"The `get \"{route}\"` helper call failed because the pre-existing handlebars render context \
was not an object (it was `{modified_context_data_as_json}`)."
))))
)),
));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::content::*;
use crate::*;
use actix_rt::System;
use actix_web::error::QueryPayloadError;
use actix_web::http::header::{self, Header, HeaderMap};
use actix_web::http::HeaderValue;
use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer};
use actix_web::http::header::{self, Header, HeaderMap};
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, http, web};
use futures::TryStreamExt;
use mime_guess::MimeGuess;
use std::cmp::Ordering;
Expand Down Expand Up @@ -1266,7 +1266,8 @@ mod tests {
"Response status was not 404"
);
assert_eq!(
response_body, "404 /not/a/real/path/so/this/should/404\nquery parameters:\nrequest headers:\n accept: text/plain",
response_body,
"404 /not/a/real/path/so/this/should/404\nquery parameters:\nrequest headers:\n accept: text/plain",
"Response body was incorrect"
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod lib;

use actix_web::client::Client as HttpClient;
use actix_web::http::{uri, Method, StatusCode};
use actix_web::http::{Method, StatusCode, uri};
use lib::*;
use operator::content::ContentDirectory;
use operator::test_lib::*;
Expand Down
Loading