Skip to main content

we_trust_s3/
lib.rs

1#![warn(missing_docs)]
2
3pub mod auth;
4pub mod codec;
5pub mod error;
6pub mod models;
7
8pub use codec::S3HttpCodec;
9pub use error::{Result, S3Error};
10pub use models::*;
11
12use futures::{SinkExt, StreamExt};
13use http::{Response, StatusCode};
14use tokio::net::TcpStream;
15use tokio_util::codec::Framed;
16use tracing::{error, info};
17use yykv_types::DsError;
18
19/// 使用 tokio Framed 完全重写的 S3 (HTTP) 连接处理器
20pub async fn handle_connection(stream: TcpStream) -> Result<()> {
21    let mut framed = Framed::new(stream, S3HttpCodec);
22    info!("New S3 connection established");
23
24    while let Some(result) = framed.next().await {
25        match result {
26            Ok(req) => {
27                info!("Received S3 request: {:?} {}", req.method(), req.uri());
28                let resp = Response::builder()
29                    .status(StatusCode::OK)
30                    .body(vec![])
31                    .map_err(|e| DsError::protocol(e.to_string()))?;
32                framed.send(resp).await?;
33            }
34            Err(e) => {
35                error!("S3 protocol error: {}", e);
36                break;
37            }
38        }
39    }
40
41    Ok(())
42}