refactor: move get_env_bool to utils.rs
This commit is contained in:
parent
3f8a33b9d6
commit
4026431403
2 changed files with 11 additions and 11 deletions
13
src/main.rs
13
src/main.rs
|
@ -34,7 +34,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
// get socket/port from env
|
// get socket/port from env
|
||||||
// backwards compat when only UDS is set
|
// backwards compat when only UDS is set
|
||||||
if get_env_bool("UDS") {
|
if utils::get_env_bool("UDS") {
|
||||||
let socket_path =
|
let socket_path =
|
||||||
env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string());
|
env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string());
|
||||||
server.bind_uds(socket_path)?
|
server.bind_uds(socket_path)?
|
||||||
|
@ -74,7 +74,7 @@ static CLIENT: Lazy<Client> = Lazy::new(|| {
|
||||||
builder
|
builder
|
||||||
};
|
};
|
||||||
|
|
||||||
if get_env_bool("IPV4_ONLY") {
|
if utils::get_env_bool("IPV4_ONLY") {
|
||||||
builder.local_address("0.0.0.0".parse().ok())
|
builder.local_address("0.0.0.0".parse().ok())
|
||||||
} else {
|
} else {
|
||||||
builder
|
builder
|
||||||
|
@ -126,13 +126,6 @@ fn is_header_allowed(header: &str) -> bool {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_env_bool(key: &str) -> bool {
|
|
||||||
match env::var(key) {
|
|
||||||
Ok(val) => val.to_lowercase() == "true" || val == "1",
|
|
||||||
Err(_) => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
if req.method() == Method::OPTIONS {
|
if req.method() == Method::OPTIONS {
|
||||||
let mut response = HttpResponse::Ok();
|
let mut response = HttpResponse::Ok();
|
||||||
|
@ -218,7 +211,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "webp", feature = "avif"))]
|
#[cfg(any(feature = "webp", feature = "avif"))]
|
||||||
let disallow_image_transcoding = get_env_bool("DISALLOW_IMAGE_TRANSCODING");
|
let disallow_image_transcoding = utils::get_env_bool("DISALLOW_IMAGE_TRANSCODING");
|
||||||
|
|
||||||
let rewrite = query.get("rewrite") != Some("false");
|
let rewrite = query.get("rewrite") != Some("false");
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ use qstring::QString;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 {
|
pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 {
|
||||||
let byte = buf[*pos];
|
let byte = buf[*pos];
|
||||||
|
@ -13,7 +14,6 @@ fn finalize_url(path: &str, query: BTreeMap<String, String>) -> String {
|
||||||
#[cfg(feature = "qhash")]
|
#[cfg(feature = "qhash")]
|
||||||
{
|
{
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::env;
|
|
||||||
|
|
||||||
let qhash = {
|
let qhash = {
|
||||||
let secret = env::var("HASH_SECRET");
|
let secret = env::var("HASH_SECRET");
|
||||||
|
@ -94,3 +94,10 @@ pub fn escape_xml(raw: &str) -> Cow<'_, str> {
|
||||||
Cow::Owned(escaped)
|
Cow::Owned(escaped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_env_bool(key: &str) -> bool {
|
||||||
|
match env::var(key) {
|
||||||
|
Ok(val) => val.to_lowercase() == "true" || val == "1",
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue