Skip to content

Commit

Permalink
[#172] 파일 기반 banner 출력 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Dec 15, 2024
1 parent 31c5fdc commit b0f62c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions rupring/src/application_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ impl ApplicationProperties {
"banner.enabled" => {
banner.enabled = value.parse::<bool>().unwrap_or(true);
}
"banner.location" => {
banner.location = Some(value.to_string());
}
"banner.charset" => {
banner.charset = value.to_string();
}
_ => {
etc.insert(key, value);
}
Expand Down
26 changes: 25 additions & 1 deletion rupring/src/core/banner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,31 @@ pub fn print_banner(application_properties: &ApplicationProperties) {
return;
}

println!("{}", DEFAULT_BANNER_TEXT);
if let Some(location) = &application_properties.banner.location {
let bytes = std::fs::read(location).expect("Failed to find banner file");

let text = match application_properties
.banner
.charset
.to_uppercase()
.as_str()
{
"UTF-8" => String::from_utf8(bytes).unwrap_or_default(),
"UTF-16" => {
let utf16_bytes = bytes
.chunks(2)
.map(|b| u16::from_le_bytes([b[0], b[1]]))
.collect::<Vec<u16>>();
String::from_utf16(&utf16_bytes).unwrap_or_default()
}
_ => String::from_utf8(bytes).unwrap_or_default(),
};

println!("{}", text);
} else {
println!("{}", DEFAULT_BANNER_TEXT);
}

print_app_info();
println!("");
}
Expand Down
3 changes: 1 addition & 2 deletions rupring_example/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ server.timeout-per-shutdown-phase=3s
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
server.compression.min-response-size=1024
server.compression.algorithm=gzip
banner.enabled=true
server.compression.algorithm=gzip

0 comments on commit b0f62c0

Please sign in to comment.