🚨 clippy pass
parent
ce82f7d6a3
commit
93bf38ec03
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
|
|
||||||
/// Machine-editable configs.
|
/// Machine-editable configs.
|
||||||
/// These are stored in the `data` directory and shouldn't be touched by
|
/// These are stored in the `data` directory and shouldn't be touched by
|
||||||
/// humans. ptth_relay will re-write them while it's running.
|
/// humans. `ptth_relay` will re-write them while it's running.
|
||||||
|
|
||||||
pub mod machine_editable {
|
pub mod machine_editable {
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -196,7 +196,7 @@ impl TryFrom <file::Config> for Config {
|
||||||
port: f.port,
|
port: f.port,
|
||||||
servers,
|
servers,
|
||||||
scraper_keys,
|
scraper_keys,
|
||||||
news_url: f.news_url.clone (),
|
news_url: f.news_url,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ fn parse_address (s: Option <&str>) -> Result <IpAddr, ConfigError> {
|
||||||
Ok (s
|
Ok (s
|
||||||
.map (|s| IpAddr::from_str (s))
|
.map (|s| IpAddr::from_str (s))
|
||||||
.transpose ().map_err (|_| ConfigError::BadServerAddress)?
|
.transpose ().map_err (|_| ConfigError::BadServerAddress)?
|
||||||
.unwrap_or (IpAddr::from ([0, 0, 0, 0]))
|
.unwrap_or_else (|| IpAddr::from ([0, 0, 0, 0]))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ fn error_reply (status: StatusCode, b: &str)
|
||||||
fn get_user_name (req: &http::request::Parts)
|
fn get_user_name (req: &http::request::Parts)
|
||||||
-> Option <String>
|
-> Option <String>
|
||||||
{
|
{
|
||||||
req.headers.get ("X-Email").map (|x| Some (x.to_str ().ok ()?.to_string ())).flatten ()
|
req.headers.get ("X-Email").and_then (|x| Some (x.to_str ().ok ()?.to_string ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clients will come here to start requests, and always park for at least
|
/// Clients will come here to start requests, and always park for at least
|
||||||
|
@ -371,7 +371,7 @@ async fn handle_unregistered_servers_internal (state: &Relay)
|
||||||
}
|
}
|
||||||
|
|
||||||
server_list.sort_by_key (|s| {
|
server_list.sort_by_key (|s| {
|
||||||
(s.name.clone (), s.tripcode.as_bytes ().clone (), now - s.seen)
|
(s.name.clone (), *s.tripcode.as_bytes (), now - s.seen)
|
||||||
});
|
});
|
||||||
server_list.dedup_by_key (|s| {
|
server_list.dedup_by_key (|s| {
|
||||||
(s.name.clone (), s.tripcode)
|
(s.name.clone (), s.tripcode)
|
||||||
|
@ -669,13 +669,13 @@ async fn check_server_api_key (state: &Relay, name: &str, api_key: &[u8])
|
||||||
let expected_human = {
|
let expected_human = {
|
||||||
let config = state.config.read ().await;
|
let config = state.config.read ().await;
|
||||||
|
|
||||||
config.servers.get (name).map (|s| s.tripcode.clone ())
|
config.servers.get (name).map (|s| s.tripcode)
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_machine = {
|
let expected_machine = {
|
||||||
let me_config = state.me_config.read ().await;
|
let me_config = state.me_config.read ().await;
|
||||||
|
|
||||||
me_config.servers.get (name).map (|s| s.tripcode.clone ())
|
me_config.servers.get (name).map (|s| s.tripcode)
|
||||||
};
|
};
|
||||||
|
|
||||||
if expected_machine.is_none () && expected_human.is_none () {
|
if expected_machine.is_none () && expected_human.is_none () {
|
||||||
|
@ -793,8 +793,7 @@ pub async fn run_relay (
|
||||||
let status_code = match &e {
|
let status_code = match &e {
|
||||||
UnknownServer => StatusCode::NOT_FOUND,
|
UnknownServer => StatusCode::NOT_FOUND,
|
||||||
BadRequest => StatusCode::BAD_REQUEST,
|
BadRequest => StatusCode::BAD_REQUEST,
|
||||||
ServerNeverResponded => StatusCode::GATEWAY_TIMEOUT,
|
ServerNeverResponded | ServerTimedOut => StatusCode::GATEWAY_TIMEOUT,
|
||||||
ServerTimedOut => StatusCode::GATEWAY_TIMEOUT,
|
|
||||||
|
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
};
|
};
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl Relay {
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
#[must_use]
|
||||||
pub fn build () -> Builder {
|
pub fn build () -> Builder {
|
||||||
Builder::default ()
|
Builder::default ()
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,11 +63,10 @@ pub fn route_url <'a> (method: &Method, path: &'a str) -> Route <'a> {
|
||||||
}
|
}
|
||||||
else if let Some (idx) = rest.find ('/') {
|
else if let Some (idx) = rest.find ('/') {
|
||||||
let listen_code = &rest [0..idx];
|
let listen_code = &rest [0..idx];
|
||||||
let path = &rest [idx..];
|
|
||||||
|
|
||||||
Route::ClientServerGet {
|
Route::ClientServerGet {
|
||||||
listen_code,
|
listen_code,
|
||||||
path,
|
path: &rest [idx..],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -202,9 +202,9 @@ async fn serve_file (
|
||||||
// consider it stale.
|
// consider it stale.
|
||||||
|
|
||||||
response.header ("cache-control".to_string (), b"no-cache,max-age=0".to_vec ());
|
response.header ("cache-control".to_string (), b"no-cache,max-age=0".to_vec ());
|
||||||
input.actual_etag.map (|etag| {
|
if let Some (etag) = input.actual_etag {
|
||||||
response.header ("etag".to_string (), etag);
|
response.header ("etag".to_string (), etag);
|
||||||
});
|
};
|
||||||
response.header (String::from ("accept-ranges"), b"bytes".to_vec ());
|
response.header (String::from ("accept-ranges"), b"bytes".to_vec ());
|
||||||
|
|
||||||
if range_requested {
|
if range_requested {
|
||||||
|
@ -236,14 +236,14 @@ struct ServeFileOutput {
|
||||||
|
|
||||||
fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput
|
fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput
|
||||||
{
|
{
|
||||||
match (&input.if_none_match, &input.actual_etag) {
|
if let (Some (if_none_match), Some (actual_etag)) = (&input.if_none_match, &input.actual_etag)
|
||||||
(Some (if_none_match), Some (actual_etag)) => if &actual_etag == if_none_match {
|
{
|
||||||
|
if actual_etag == if_none_match {
|
||||||
return ServeFileOutput {
|
return ServeFileOutput {
|
||||||
status_code: StatusCode::NotModified,
|
status_code: StatusCode::NotModified,
|
||||||
should_send_body: false,
|
should_send_body: false,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! input.client_wants_body {
|
if ! input.client_wants_body {
|
||||||
|
@ -268,14 +268,14 @@ fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput
|
||||||
|
|
||||||
async fn get_file_etag (f: &File) -> Option <String>
|
async fn get_file_etag (f: &File) -> Option <String>
|
||||||
{
|
{
|
||||||
let md = f.metadata ().await.ok ()?;
|
|
||||||
|
|
||||||
#[derive (Serialize)]
|
#[derive (Serialize)]
|
||||||
struct CacheBreaker {
|
struct CacheBreaker {
|
||||||
len: u64,
|
len: u64,
|
||||||
mtime: std::time::SystemTime,
|
mtime: std::time::SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let md = f.metadata ().await.ok ()?;
|
||||||
|
|
||||||
let buf = rmp_serde::to_vec (&CacheBreaker {
|
let buf = rmp_serde::to_vec (&CacheBreaker {
|
||||||
len: md.len (),
|
len: md.len (),
|
||||||
mtime: md.modified ().ok ()?,
|
mtime: md.modified ().ok ()?,
|
||||||
|
|
|
@ -185,7 +185,7 @@ async fn handle_req_resp (
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Config for ptth_server and the file server module
|
/// Config for `ptth_server` and the file server module
|
||||||
///
|
///
|
||||||
/// This is a complete config.
|
/// This is a complete config.
|
||||||
/// The bin frontend is allowed to load an incomplete config from
|
/// The bin frontend is allowed to load an incomplete config from
|
||||||
|
@ -230,7 +230,7 @@ impl ConfigFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Config for ptth_server itself
|
/// Config for `ptth_server` itself
|
||||||
|
|
||||||
#[derive (Default)]
|
#[derive (Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
Loading…
Reference in New Issue