diff --git a/Cargo.toml b/Cargo.toml index e0a1bc2..876a1e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "2.3.0" description = "A Rust HTTP server for Python applications" authors = ["Giovanni Barillari "] license = "BSD-3-Clause" -edition = "2021" +edition = "2024" keywords = ["web", "asyncio"] diff --git a/src/asgi/callbacks.rs b/src/asgi/callbacks.rs index 1b5360b..bf8d84d 100644 --- a/src/asgi/callbacks.rs +++ b/src/asgi/callbacks.rs @@ -4,7 +4,7 @@ use std::{ net::SocketAddr, sync::{Arc, OnceLock}, }; -use tokio::sync::{oneshot, Notify}; +use tokio::sync::{Notify, oneshot}; use super::{ io::{ASGIHTTPProtocol as HTTPProtocol, ASGIWebsocketProtocol as WebsocketProtocol, WebsocketDetachedTransport}, @@ -12,7 +12,7 @@ use super::{ }; use crate::{ callbacks::ArcCBScheduler, - http::{response_500, HTTPResponse}, + http::{HTTPResponse, response_500}, runtime::{Runtime, RuntimeRef}, utils::log_application_callable_exception, ws::{HyperWebsocket, UpgradeData}, diff --git a/src/asgi/conversion.rs b/src/asgi/conversion.rs index bb93e8e..997d909 100644 --- a/src/asgi/conversion.rs +++ b/src/asgi/conversion.rs @@ -1,7 +1,7 @@ use pyo3::{ + IntoPyObjectExt, prelude::*, types::{PyBytes, PyDict}, - IntoPyObjectExt, }; use tokio_tungstenite::tungstenite::Message; diff --git a/src/asgi/http.rs b/src/asgi/http.rs index ec91a11..7903dd0 100644 --- a/src/asgi/http.rs +++ b/src/asgi/http.rs @@ -1,14 +1,14 @@ use http_body_util::BodyExt; -use hyper::{header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder, StatusCode}; +use hyper::{StatusCode, header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder}; use std::{net::SocketAddr, sync::Arc}; -use tokio::sync::{mpsc, Notify}; +use tokio::sync::{Notify, mpsc}; use super::callbacks::{call_http, call_ws}; use crate::{ callbacks::ArcCBScheduler, - http::{empty_body, response_500, HTTPRequest, HTTPResponse, HV_SERVER}, + http::{HTTPRequest, HTTPResponse, HV_SERVER, empty_body, response_500}, runtime::RuntimeRef, - ws::{is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade, UpgradeData}, + ws::{UpgradeData, is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade}, }; const SCHEME_HTTPS: &str = "https"; diff --git a/src/asgi/io.rs b/src/asgi/io.rs index ae90048..c6c2cf7 100644 --- a/src/asgi/io.rs +++ b/src/asgi/io.rs @@ -1,32 +1,31 @@ use anyhow::Result; -use futures::{sink::SinkExt, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, sink::SinkExt}; use http_body_util::BodyExt; use hyper::{ - body, + Response, StatusCode, body, header::{HeaderMap, HeaderName, HeaderValue, SERVER as HK_SERVER}, - Response, StatusCode, }; use pyo3::{prelude::*, pybacked::PyBackedBytes, types::PyDict}; use std::{ borrow::Cow, - sync::{atomic, Arc, Mutex}, + sync::{Arc, Mutex, atomic}, }; use tokio::{ fs::File, - sync::{mpsc, oneshot, Mutex as AsyncMutex, Notify}, + sync::{Mutex as AsyncMutex, Notify, mpsc, oneshot}, }; use tokio_tungstenite::tungstenite::Message; use tokio_util::io::ReaderStream; use super::{ - errors::{error_flow, error_message, UnsupportedASGIMessage}, + errors::{UnsupportedASGIMessage, error_flow, error_message}, types::ASGIMessageType, }; use crate::{ conversion::FutureResultToPy, - http::{response_404, HTTPResponse, HTTPResponseBody, HV_SERVER}, + http::{HTTPResponse, HTTPResponseBody, HV_SERVER, response_404}, runtime::{ - done_future_into_py, empty_future_into_py, err_future_into_py, future_into_py_futlike, Runtime, RuntimeRef, + Runtime, RuntimeRef, done_future_into_py, empty_future_into_py, err_future_into_py, future_into_py_futlike, }, ws::{HyperWebsocket, UpgradeData, WSRxStream, WSTxStream}, }; diff --git a/src/asgi/serve.rs b/src/asgi/serve.rs index 3d9b3ad..627066f 100644 --- a/src/asgi/serve.rs +++ b/src/asgi/serve.rs @@ -6,7 +6,7 @@ use super::http::{handle, handle_ws}; use crate::callbacks::CallbackScheduler; use crate::conversion::{worker_http1_config_from_py, worker_http2_config_from_py}; use crate::tcp::SocketHolder; -use crate::workers::{gen_serve_match, gen_serve_methods, WorkerConfig, WorkerSignal}; +use crate::workers::{WorkerConfig, WorkerSignal, gen_serve_match, gen_serve_methods}; #[pyclass(frozen, module = "granian._granian")] pub struct ASGIWorker { diff --git a/src/asgi/types.rs b/src/asgi/types.rs index c424b82..600bfe9 100644 --- a/src/asgi/types.rs +++ b/src/asgi/types.rs @@ -1,4 +1,4 @@ -use hyper::{body, HeaderMap}; +use hyper::{HeaderMap, body}; use tokio_tungstenite::tungstenite::Message; pub(crate) enum ASGIMessageType { diff --git a/src/blocking.rs b/src/blocking.rs index 26d56a8..898f622 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -1,7 +1,7 @@ use crossbeam_channel as channel; use pyo3::prelude::*; use std::{ - sync::{atomic, Arc}, + sync::{Arc, atomic}, thread, time, }; diff --git a/src/callbacks.rs b/src/callbacks.rs index de5f9dd..3bc0101 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -1,5 +1,5 @@ -use pyo3::{exceptions::PyStopIteration, prelude::*, types::PyDict, IntoPyObjectExt}; -use std::sync::{atomic, Arc, OnceLock, RwLock}; +use pyo3::{IntoPyObjectExt, exceptions::PyStopIteration, prelude::*, types::PyDict}; +use std::sync::{Arc, OnceLock, RwLock, atomic}; use tokio::sync::Notify; use crate::{asyncio::copy_context, conversion::FutureResultToPy}; @@ -260,6 +260,7 @@ pub(crate) struct CallbackSchedulerState { } impl CallbackSchedulerState { + #[allow(unsafe_op_in_unsafe_fn)] unsafe fn add_waker(self: Arc, py: Python, fut: *mut pyo3::ffi::PyObject, fut_cbm: *mut pyo3::ffi::PyObject) { let waker = Py::new(py, CallbackSchedulerWaker { state: self.clone() }).unwrap(); let ctxd = PyDict::new(py); diff --git a/src/conversion.rs b/src/conversion.rs index 249697e..70a399c 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -1,4 +1,4 @@ -use pyo3::{prelude::*, IntoPyObjectExt}; +use pyo3::{IntoPyObjectExt, prelude::*}; use crate::workers::{HTTP1Config, HTTP2Config}; diff --git a/src/files.rs b/src/files.rs index 2a5e455..472b1c7 100644 --- a/src/files.rs +++ b/src/files.rs @@ -2,14 +2,14 @@ use anyhow::Result; use futures::TryStreamExt; use http_body_util::BodyExt; use hyper::{ - header::{HeaderValue, SERVER as HK_SERVER}, HeaderMap, StatusCode, + header::{HeaderValue, SERVER as HK_SERVER}, }; use std::{io, path::Path}; use tokio::fs::File; use tokio_util::io::ReaderStream; -use crate::http::{response_404, HTTPResponse, HV_SERVER}; +use crate::http::{HTTPResponse, HV_SERVER, response_404}; #[inline(always)] pub(crate) fn match_static_file(uri_path: &str, prefix: &str, mount_point: &str) -> Option> { diff --git a/src/http.rs b/src/http.rs index f1139ce..61c8147 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,8 +1,8 @@ use http_body_util::BodyExt; use hyper::{ + Response, body::Bytes, header::{HeaderValue, SERVER as HK_SERVER}, - Response, }; pub(crate) type HTTPRequest = hyper::Request; diff --git a/src/rsgi/callbacks.rs b/src/rsgi/callbacks.rs index fc9bee6..90744a3 100644 --- a/src/rsgi/callbacks.rs +++ b/src/rsgi/callbacks.rs @@ -1,6 +1,6 @@ use pyo3::prelude::*; use std::sync::{Arc, OnceLock}; -use tokio::sync::{oneshot, Notify}; +use tokio::sync::{Notify, oneshot}; use super::{ io::{RSGIHTTPProtocol as HTTPProtocol, RSGIWebsocketProtocol as WebsocketProtocol, WebsocketDetachedTransport}, diff --git a/src/rsgi/conversion.rs b/src/rsgi/conversion.rs index f3b520b..e27842b 100644 --- a/src/rsgi/conversion.rs +++ b/src/rsgi/conversion.rs @@ -1,7 +1,7 @@ use pyo3::{ + IntoPyObjectExt, prelude::*, types::{PyBytes, PyString}, - IntoPyObjectExt, }; use tokio_tungstenite::tungstenite::Message; diff --git a/src/rsgi/http.rs b/src/rsgi/http.rs index 5e8a625..c2bd677 100644 --- a/src/rsgi/http.rs +++ b/src/rsgi/http.rs @@ -1,8 +1,8 @@ use futures::sink::SinkExt; use http_body_util::BodyExt; -use hyper::{header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder, StatusCode}; +use hyper::{StatusCode, header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder}; use std::{net::SocketAddr, sync::Arc}; -use tokio::sync::{mpsc, Notify}; +use tokio::sync::{Notify, mpsc}; use super::{ callbacks::{call_http, call_ws}, @@ -10,9 +10,9 @@ use super::{ }; use crate::{ callbacks::ArcCBScheduler, - http::{empty_body, response_500, HTTPRequest, HTTPResponse, HV_SERVER}, + http::{HTTPRequest, HTTPResponse, HV_SERVER, empty_body, response_500}, runtime::RuntimeRef, - ws::{is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade, UpgradeData}, + ws::{UpgradeData, is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade}, }; macro_rules! build_scope { diff --git a/src/rsgi/io.rs b/src/rsgi/io.rs index c096617..bc3f360 100644 --- a/src/rsgi/io.rs +++ b/src/rsgi/io.rs @@ -1,12 +1,12 @@ -use futures::{sink::SinkExt, StreamExt}; +use futures::{StreamExt, sink::SinkExt}; use http_body_util::BodyExt; use hyper::body; use pyo3::{prelude::*, pybacked::PyBackedStr}; use std::{ borrow::Cow, - sync::{atomic, Arc, Mutex, RwLock}, + sync::{Arc, Mutex, RwLock, atomic}, }; -use tokio::sync::{mpsc, oneshot, Mutex as AsyncMutex, Notify}; +use tokio::sync::{Mutex as AsyncMutex, Notify, mpsc, oneshot}; use tokio_tungstenite::tungstenite::Message; use super::{ @@ -15,7 +15,7 @@ use super::{ }; use crate::{ conversion::FutureResultToPy, - runtime::{empty_future_into_py, err_future_into_py, future_into_py_futlike, RuntimeRef}, + runtime::{RuntimeRef, empty_future_into_py, err_future_into_py, future_into_py_futlike}, ws::{HyperWebsocket, UpgradeData, WSRxStream, WSTxStream}, }; diff --git a/src/rsgi/serve.rs b/src/rsgi/serve.rs index 112c11e..ce622b0 100644 --- a/src/rsgi/serve.rs +++ b/src/rsgi/serve.rs @@ -6,7 +6,7 @@ use super::http::{handle, handle_ws}; use crate::callbacks::CallbackScheduler; use crate::conversion::{worker_http1_config_from_py, worker_http2_config_from_py}; use crate::tcp::SocketHolder; -use crate::workers::{gen_serve_match, gen_serve_methods, WorkerConfig, WorkerSignal}; +use crate::workers::{WorkerConfig, WorkerSignal, gen_serve_match, gen_serve_methods}; #[pyclass(frozen, module = "granian._granian")] pub struct RSGIWorker { diff --git a/src/rsgi/types.rs b/src/rsgi/types.rs index 8bf1374..3d7c101 100644 --- a/src/rsgi/types.rs +++ b/src/rsgi/types.rs @@ -2,10 +2,10 @@ use anyhow::Result; use futures::TryStreamExt; use http_body_util::BodyExt; use hyper::{ + Method, Uri, Version, body::Bytes, header::{HeaderMap, HeaderName, HeaderValue, SERVER as HK_SERVER}, http::uri::Authority, - Method, Uri, Version, }; use percent_encoding::percent_decode_str; use pyo3::types::{PyBytes, PyIterator, PyList, PyString}; @@ -14,7 +14,7 @@ use std::{borrow::Cow, net::SocketAddr}; use tokio::fs::File; use tokio_util::io::ReaderStream; -use crate::http::{empty_body, response_404, HTTPResponseBody, HV_SERVER}; +use crate::http::{HTTPResponseBody, HV_SERVER, empty_body, response_404}; const RSGI_PROTO_VERSION: &str = "1.5"; diff --git a/src/runtime.rs b/src/runtime.rs index 1af521a..cdb310d 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -1,4 +1,4 @@ -use pyo3::{prelude::*, IntoPyObjectExt}; +use pyo3::{IntoPyObjectExt, prelude::*}; use std::{ future::Future, sync::{Arc, Mutex}, diff --git a/src/tcp.rs b/src/tcp.rs index b3f9e94..18a7625 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use pyo3::{prelude::*, IntoPyObjectExt}; +use pyo3::{IntoPyObjectExt, prelude::*}; use std::net::{IpAddr, SocketAddr, TcpListener}; #[cfg(unix)] diff --git a/src/tls.rs b/src/tls.rs index d701234..7ee55a6 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use std::{ fs, io, iter::Iterator, @@ -6,17 +6,17 @@ use std::{ sync::Arc, }; use tls_listener::{ + TlsListener, rustls::{ + TlsAcceptor, rustls::{ pki_types::{ - pem::PemObject, CertificateDer as Certificate, CertificateRevocationListDer as CRL, - PrivateKeyDer as PrivateKey, + CertificateDer as Certificate, CertificateRevocationListDer as CRL, PrivateKeyDer as PrivateKey, + pem::PemObject, }, server::ServerConfig, }, - TlsAcceptor, }, - TlsListener, }; pub(crate) fn tls_listener( diff --git a/src/ws.rs b/src/ws.rs index 27118eb..3555bf8 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -1,8 +1,8 @@ use http_body_util::BodyExt; use hyper::{ - header::{HeaderName, HeaderValue, CONNECTION, UPGRADE}, - http::response::Builder, Request, Response, StatusCode, + header::{CONNECTION, HeaderName, HeaderValue, UPGRADE}, + http::response::Builder, }; use pin_project_lite::pin_project; use std::{ @@ -12,13 +12,13 @@ use std::{ }; use tokio::sync::mpsc; use tokio_tungstenite::{ + WebSocketStream, tungstenite::{ + Error as TungsteniteError, Message, error::ProtocolError, handshake::derive_accept_key, protocol::{Role, WebSocketConfig}, - Error as TungsteniteError, Message, }, - WebSocketStream, }; use super::http::HTTPResponse; diff --git a/src/wsgi/callbacks.rs b/src/wsgi/callbacks.rs index e78ac06..81026c6 100644 --- a/src/wsgi/callbacks.rs +++ b/src/wsgi/callbacks.rs @@ -1,7 +1,6 @@ use hyper::{ - body, header, + HeaderMap, Version, body, header, http::{request, uri::Authority}, - HeaderMap, Version, }; use itertools::Itertools; use percent_encoding::percent_decode_str; @@ -15,7 +14,7 @@ use tokio::sync::oneshot; use super::{io::WSGIProtocol, types::WSGIBody}; use crate::{ callbacks::ArcCBScheduler, - http::{empty_body, HTTPResponseBody}, + http::{HTTPResponseBody, empty_body}, runtime::{Runtime, RuntimeRef}, utils::log_application_callable_exception, }; diff --git a/src/wsgi/http.rs b/src/wsgi/http.rs index 574e36e..e8f021b 100644 --- a/src/wsgi/http.rs +++ b/src/wsgi/http.rs @@ -5,7 +5,7 @@ use tokio::sync::Notify; use super::callbacks::call_http; use crate::{ callbacks::ArcCBScheduler, - http::{response_500, HTTPRequest, HTTPResponse, HTTPResponseBody}, + http::{HTTPRequest, HTTPResponse, HTTPResponseBody, response_500}, runtime::RuntimeRef, };