1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-05-20 01:08:10 +00:00
actix-web/actix-http/src/h1/mod.rs

94 lines
1.7 KiB
Rust
Raw Normal View History

2021-02-11 22:39:54 +00:00
//! HTTP/1 protocol implementation.
2021-08-12 19:18:09 +00:00
2019-04-02 18:11:32 +00:00
use bytes::{Bytes, BytesMut};
2021-08-12 19:18:09 +00:00
mod chunked;
mod client;
2018-10-05 03:02:10 +00:00
mod codec;
mod decoder;
mod dispatcher;
2022-01-27 06:06:55 +00:00
#[cfg(test)]
mod dispatcher_tests;
2018-10-05 17:03:10 +00:00
mod encoder;
2019-04-05 23:46:44 +00:00
mod expect;
mod payload;
2018-10-05 03:02:10 +00:00
mod service;
2022-01-31 17:30:34 +00:00
mod timer;
2019-04-08 21:51:16 +00:00
mod upgrade;
mod utils;
2018-10-05 03:02:10 +00:00
2023-07-17 01:38:12 +00:00
pub use self::{
client::{ClientCodec, ClientPayloadCodec},
codec::Codec,
dispatcher::Dispatcher,
expect::ExpectHandler,
payload::Payload,
service::{H1Service, H1ServiceHandler},
upgrade::UpgradeHandler,
utils::SendResponse,
};
#[derive(Debug)]
/// Codec message
pub enum Message<T> {
2022-01-31 17:30:34 +00:00
/// HTTP message.
Item(T),
2022-01-31 17:30:34 +00:00
/// Payload chunk.
Chunk(Option<Bytes>),
}
impl<T> From<T> for Message<T> {
fn from(item: T) -> Self {
Message::Item(item)
}
}
/// Incoming request type
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageType {
None,
Payload,
2018-11-14 06:53:30 +00:00
Stream,
}
2018-11-06 03:32:03 +00:00
2019-04-02 18:11:32 +00:00
const LW: usize = 2 * 1024;
const HW: usize = 32 * 1024;
pub(crate) fn reserve_readbuf(src: &mut BytesMut) {
let cap = src.capacity();
if cap < LW {
src.reserve(HW - cap);
}
}
2018-11-06 03:32:03 +00:00
#[cfg(test)]
mod tests {
use super::*;
use crate::Request;
2018-11-06 03:32:03 +00:00
impl Message<Request> {
pub fn message(self) -> Request {
match self {
Message::Item(req) => req,
_ => panic!("error"),
}
}
pub fn chunk(self) -> Bytes {
match self {
Message::Chunk(Some(data)) => data,
_ => panic!("error"),
}
}
pub fn eof(self) -> bool {
match self {
Message::Chunk(None) => true,
Message::Chunk(Some(_)) => false,
_ => panic!("error"),
}
}
}
}