headers reference self eefefff

This commit is contained in:
MeexReay 2024-09-13 18:50:04 +03:00
parent 6d8d5b5fab
commit 291d2a88d0
4 changed files with 15 additions and 16 deletions

View File

@ -19,4 +19,4 @@ threadpool = "1.8.1"
lazy_static = "1.5.0"
[features]
http_rrs = []
flowgate = []

View File

@ -4,7 +4,7 @@ use std::{future::Future, pin::Pin, sync::Arc};
use tokio::net::TcpStream;
use tokio_io_timeout::TimeoutStream;
#[cfg(feature = "http_rrs")]
#[cfg(feature = "flowgate")]
use {super::read_line_lf, std::net::{ToSocketAddrs, SocketAddr}};
pub type Handler<T> = Box<dyn Fn(Arc<T>, TimeoutStream<TcpStream>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>;
@ -49,9 +49,9 @@ macro_rules! pin_handler {
};
}
#[cfg(feature = "http_rrs")]
/// HTTP_RRS handler
pub async fn handler_http_rrs<S: HttpServer + Send + 'static + Sync>(
#[cfg(feature = "flowgate")]
/// Flowgate handler
pub async fn handler_flowgate<S: HttpServer + Send + 'static + Sync>(
server: Arc<S>,
mut sock: Stream,
) {

View File

@ -37,8 +37,8 @@ impl Headers {
}
}
pub fn contains(self, header: impl ToString) -> bool {
for (k, _) in self.entries {
pub fn contains(&self, header: impl ToString) -> bool {
for (k, _) in &self.entries {
if k.to_lowercase() == header.to_string().to_lowercase() {
return true;
}
@ -46,10 +46,10 @@ impl Headers {
return false;
}
pub fn get(self, key: impl ToString) -> Option<String> {
for (k, v) in self.entries {
pub fn get(&self, key: impl ToString) -> Option<String> {
for (k, v) in &self.entries {
if k.to_lowercase() == key.to_string().to_lowercase() {
return Some(v);
return Some(v.clone());
}
}
return None;
@ -74,19 +74,19 @@ impl Headers {
}
}
pub fn keys(self) -> Vec<String> {
pub fn keys(&self) -> Vec<String> {
self.entries.iter().map(|e| e.0.clone()).collect()
}
pub fn values(self) -> Vec<String> {
pub fn values(&self) -> Vec<String> {
self.entries.iter().map(|e| e.1.clone()).collect()
}
pub fn entries(self) -> Vec<(String, String)> {
return self.entries;
pub fn entries(&self) -> Vec<(String, String)> {
return self.entries.clone();
}
pub fn len(self) -> usize {
pub fn len(&self) -> usize {
return self.entries.len();
}

View File

@ -51,7 +51,6 @@ async fn read_line_crlf(data: &mut (impl AsyncReadExt + Unpin)) -> Result<String
}
}
#[cfg(feature = "http_rrs")]
async fn read_line_lf(data: &mut (impl AsyncReadExt + Unpin)) -> Result<String, HttpError> {
match read_line(data).await {
Ok(i) => Ok(i[..i.len() - 1].to_string()),