Skip to content

Commit a91f283

Browse files
committed
chore: drop axum
Nothing was left of it but re-exports of http, bytes and one body helper. The Router went when the server started driving hyper directly to get HTTP/2 and TLS. Depending on those three crates instead takes the tree from 144 to 102.
1 parent 235666d commit a91f283

4 files changed

Lines changed: 21 additions & 150 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
axum = { version = "0.8", default-features = false, features = ["http1", "http2", "tokio"] }
98
hyper = { version = "1", default-features = false, features = ["http1", "http2", "server"] }
9+
http = "1"
10+
bytes = "1"
1011
hyper-util = { version = "0.1", default-features = false, features = ["server-auto", "server-graceful", "tokio"] }
1112
tokio = { version = "1", default-features = false, features = ["rt", "net", "signal", "time", "macros"] }
1213
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] }
1314
rustls-pemfile = "2"
14-
tower-service = "0.3"
1515
http-body-util = "0.1"
1616
socket2 = { version = "0.5", features = ["all"] }
1717
libc = "0.2"

src/php/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ffi::CString;
22

3-
use axum::body::Bytes;
3+
use bytes::Bytes;
44
use tokio::sync::mpsc::Sender;
55
use tokio::sync::oneshot;
66

src/server.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use std::net::SocketAddr;
33
use std::sync::atomic::Ordering;
44
use std::sync::Arc;
55

6-
use axum::body::{Body, Bytes};
7-
use axum::http::{HeaderName, HeaderValue, Request, Response, StatusCode};
6+
use bytes::Bytes;
7+
use http::{HeaderName, HeaderValue, Request, Response, StatusCode};
8+
use http_body_util::combinators::BoxBody;
9+
use http_body_util::{BodyExt, Empty, Full, Limited};
810
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
911
use hyper_util::server::conn::auto;
1012
use hyper_util::server::graceful::GracefulShutdown;
@@ -13,9 +15,14 @@ use tokio_rustls::rustls::pki_types::{CertificateDer, PrivateKeyDer};
1315
use tokio_rustls::rustls::ServerConfig;
1416
use tokio_rustls::TlsAcceptor;
1517

18+
use hyper::body::Incoming;
19+
1620
use crate::config::Config;
1721
use crate::runtime::{Runtime, SHUTDOWN};
1822

23+
/// One response body type covering both a buffered `Vec` and a live chunk channel.
24+
type Body = BoxBody<Bytes, std::convert::Infallible>;
25+
1926
static MAX_BODY: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
2027

2128
pub struct Job {
@@ -108,7 +115,7 @@ pub fn bind(addr: SocketAddr, backlog: i32) -> std::io::Result<std::net::TcpList
108115
Ok(socket.into())
109116
}
110117

111-
async fn dispatch(peer: SocketAddr, req: Request<hyper::body::Incoming>) -> Response<Body> {
118+
async fn dispatch(peer: SocketAddr, req: Request<Incoming>) -> Response<Body> {
112119
let (parts, body) = req.into_parts();
113120

114121
if parts.uri.path() == "/__stoke_ping" {
@@ -120,8 +127,8 @@ async fn dispatch(peer: SocketAddr, req: Request<hyper::body::Incoming>) -> Resp
120127
}
121128

122129
let max_body = MAX_BODY.load(Ordering::Relaxed);
123-
let body = match axum::body::to_bytes(Body::new(body), max_body).await {
124-
Ok(bytes) => bytes,
130+
let body = match Limited::new(body, max_body).collect().await {
131+
Ok(collected) => collected.to_bytes(),
125132
Err(_) => return render(Reply::plain(413, "Content Too Large")),
126133
};
127134

@@ -155,7 +162,7 @@ async fn dispatch(peer: SocketAddr, req: Request<hyper::body::Incoming>) -> Resp
155162
path,
156163
query,
157164
target,
158-
version_minor: if parts.version == axum::http::Version::HTTP_10 {
165+
version_minor: if parts.version == http::Version::HTTP_10 {
159166
0
160167
} else {
161168
1
@@ -215,16 +222,16 @@ fn render(reply: Reply) -> Response<Body> {
215222
}
216223

217224
let body = match reply.body {
218-
ReplyBody::Full(bytes) => Body::from(bytes),
219-
ReplyBody::Stream(chunks) => Body::new(ChannelBody { chunks }),
225+
ReplyBody::Full(bytes) => Full::new(Bytes::from(bytes)).boxed(),
226+
ReplyBody::Stream(chunks) => ChannelBody { chunks }.boxed(),
220227
};
221228

222229
builder
223230
.body(body)
224231
.unwrap_or_else(|_| {
225232
Response::builder()
226233
.status(StatusCode::INTERNAL_SERVER_ERROR)
227-
.body(Body::empty())
234+
.body(Empty::new().boxed())
228235
.expect("fallback response")
229236
})
230237
}

0 commit comments

Comments
 (0)