dataframe struc definition

This commit is contained in:
maxstrb 2025-10-21 20:16:37 +02:00
parent 145cbb9243
commit 8f12a03e46
5 changed files with 78 additions and 7 deletions

View file

@ -1,5 +1,5 @@
use crate::{
request::{Connection, Protocol, Request, RequestHeader},
request::{Connection, Protocol, Request, RequestHeader, Upgrade},
response::Response,
};
@ -13,7 +13,30 @@ pub struct WebsocketConnection {
stream: TcpStream,
}
struct DataFrame {
is_final: bool,
extension_1: bool,
extension_2: bool,
extension_3: bool,
frame_type: FrameType,
is_masked: bool,
data: Vec<u8>,
}
enum FrameType {}
impl WebsocketConnection {
pub async fn send_message() -> io::Result<()> {
todo!()
}
pub async fn read_next_message() {
todo!()
}
pub async fn initialize_connection(
req: Request,
mut stream: TcpStream,
@ -54,7 +77,21 @@ impl WebsocketConnection {
let result = hasher.finalize();
let result = BASE64_STANDARD.encode(result);
Response::new().with_code(200).with_header(crate::response::ResponseHeader::Location)
Response::new()
.with_code(crate::response::ResponseCode::SwitchingProtocols)
.with_header(crate::response::ResponseHeader::Upgrade(Upgrade {
protocol: Protocol::Websocket,
version: "".into(),
}))
.with_header(crate::response::ResponseHeader::Connection(
Connection::Upgrade,
))
.with_header(crate::response::ResponseHeader::Other {
header_name: "Sec-WebSocket-Accept".into(),
header_value: result.into(),
})
.respond(&mut stream)
.await?;
Ok(Self { stream })
} else {